Framework · Agent SDKs

Instructor

Get reliable, type-safe structured data from any LLM by patching the provider client to accept a Pydantic response_model, validate the response, and retry with validation feedback when the model violates the schema.

Description

Instructor is the MIT-licensed library that turns Pydantic models into the contract between application code and an LLM. It patches each supported provider's chat-completion client to add response_model, max_retries, and context parameters, then wraps the call: when validation fails, the library reasks the model with the validation error attached so the next attempt converges on a valid object. Modes (TOOLS, JSON, MD_JSON, FUNCTIONS) select the underlying provider mechanism; from_provider exposes a unified entry point across 15+ providers (OpenAI, Anthropic, Google, Mistral, Cohere, Ollama, DeepSeek, Groq, and more). Instructor is positioned as an extraction library, not an agent framework: 'Instructor for extraction, PydanticAI for agents.'

Solution

Single-call extraction with internal retry, not an agent loop. The patched create() runs the request, parses the response into the response_model, validates it, and on ValidationError reasks the model up to max_retries times. There is no multi-step tool loop, no handoff, no session memory; agentic behaviour requires composing Instructor inside a higher-level framework.

Primary use cases

  • extracting typed objects from LLM responses
  • schema-validated tool-call arguments before execution
  • multi-provider structured-output code that does not change when swapping models
  • self-correcting JSON output via validation-feedback retries

Open the full interactive page

Diagram, neighbourhood map, code examples, related patterns and full provenance.