What is Instructor?
Instructor patches LLM client libraries so they return validated Pydantic objects instead of raw text. Supports retries, streaming output, and partial responses.
In one sentence: Instructor extracts structured data from LLMs using Pydantic models, supporting OpenAI, Anthropic, Gemini, and local models.
Core Patterns
1. Multi-Provider Support
Works with OpenAI, Anthropic, Gemini, Ollama, and more — switch with a single line.
2. Nested Complex Types
Supports nested models, lists, optional fields, and the full power of Pydantic.
3. Streaming Partial Results
Fields fill in progressively — great for real-time display of large structured outputs.
4. Auto-Retry
On validation failure, automatically feeds the error back to the LLM for regeneration.
FAQ
Q: Does it support Claude?
A: Yes, via instructor.from_anthropic() using tool-use mode.
Q: Performance overhead? A: Minimal — it's a thin wrapper. Retries add latency only on validation failure.