Instructor
Open-source Python library for structured LLM outputs via Pydantic models, supporting 12+ providers including OpenAI and Anthropic, with 10k+ GitHub stars.
Instructor is a Python library by Jason Liu that makes it simple to extract validated, structured Pydantic objects from any LLM response, replacing manual JSON parsing with type-safe models. It wraps any OpenAI-compatible provider and automatically handles retries when the model returns malformed output, re-prompting with the validation error to guide correction. Instructor supports 12+ providers including OpenAI, Anthropic, Google Gemini, Cohere, LiteLLM, and local models via Ollama, using each provider's native function calling or JSON mode. The project crossed 10,000 GitHub stars and is one of the most-downloaded Python AI libraries, used by teams building production extraction, classification, and RAG pipelines.
Key Features
- Structured output extraction using Pydantic models with automatic validation and retries
- Support for 12+ providers: OpenAI, Anthropic, Gemini, Cohere, and local models via Ollama
- Streaming support for real-time partial object validation as tokens arrive
- Tenacity-based retry logic for handling validation failures and coercing partial outputs
- Mode selection for function calling, JSON mode, and tool use per provider capability
- Hooks and logging callbacks for tracing every LLM call and validation attempt
Use Cases
- Backend engineers extracting structured entities from unstructured text without brittle parsing
- Data engineers building classification pipelines that output validated enum and typed fields
- Teams building RAG systems that need guaranteed JSON schema compliance on every LLM response
- Developers migrating manual prompt parsing to type-safe Pydantic extraction across providers
Pros
- Automatic retry with validation error feedback eliminates manual parsing failure handling
- 10k+ GitHub stars and the most actively used Python library for structured LLM extraction
- Provider-agnostic API - swap OpenAI for Anthropic or a local model with one line change
Cons
- Each retry adds latency and API cost - complex schemas can require multiple model calls
- Not a standalone product - requires an existing LLM API subscription to function
- Large Pydantic models with many optional fields can confuse weaker models into partial outputs
Instructor Alternatives
Explore similar tools and alternatives
Looking for alternatives to Instructor? Here are some similar tools you might like:
LangChain
The most widely adopted framework for building LLM-powered applications - 100K+ GitHub stars, supports every major LLM and vector store.
LlamaIndex
Leading open-source data framework for building LLM applications with RAG and agents - 40,000+ GitHub stars and a managed LlamaCloud service.
PydanticAI
Agent framework by the Pydantic team that brings full Python type safety to building AI agents, with first-class OpenAI, Anthropic, and Gemini support.
Ready to try Instructor?
Visit the official website to explore all features and get started with Instructor today.
Reviews
0 reviews for Instructor
Based on 0 reviews
Share your experience
Log in to write a review for Instructor
Ito
Only code review that runs your code. Provides runtime analysis with evidence (logs, video, screenshot) to show how code changes application actually work. Back-end, front-end, api, integration.
Cursor
AI-native code editor built on VS Code with built-in AI chat, autocomplete, and codebase understanding.
GitHub Copilot
AI pair programmer by GitHub/OpenAI that suggests code completions, functions, and entire files in your IDE.
Have an AI Tool?
List your AI tool for free, or go featured for top placement in your category - and reach thousands of potential users.
Submit Your Tool