Key Features
Type-Safe Extraction
Define output schema with Pydantic, get validated objects back:
class Contact(BaseModel):
name: str
email: str
company: Optional[str] = NoneAutomatic Retries
If the LLM returns invalid data, Instructor retries with the validation error as context:
client.chat.completions.create(
response_model=Contact,
max_retries=3, # auto-retry on validation failure
...
)Streaming & Partial Responses
Stream structured objects as they're generated — great for UIs.
Multi-Provider
One API across OpenAI, Anthropic, Google Gemini, Ollama, Mistral, and more.
Complex Schemas
Nested models, lists, enums, optional fields, custom validators — full Pydantic support.
FAQ
Q: What is Instructor? A: A Python library that gets structured, validated outputs from LLMs using Pydantic models. Handles prompting, parsing, validation, and retries. 12.6K+ stars.
Q: Does it work with Claude? A: Yes, Instructor supports Anthropic Claude, OpenAI, Google Gemini, Ollama, and many more providers.