Instructor
A small Python library that forces a model output into a Pydantic schema and retries automatically when the response fails validation.
Tested on Claude Sonnet · 4.5 ·
LIBRARY · Free, open source
Instructor solves one common problem: getting a model to return data that matches a schema you defined, and not a JSON-shaped guess. Define a Pydantic model, pass it in, get back a validated instance. If the first response does not parse, it retries with the validation error fed back to the model.
It is a thin layer and no framework. It wraps a single call and does not dictate how you structure an application. That narrow scope makes it easy to add to existing code with no rewrite.
Notes from the author
Write specific Pydantic field descriptions. The model reads them to understand the schema, so they do more than document the code for other developers.
For information only, not professional advice. You use it at your own risk and we are not liable for any loss or damage. See the disclaimer.
Tagged