Most popular Python library for getting structured, validated outputs from LLMs by combining pydantic schemas with provider-native function calling.
Most popular Python library for getting structured, validated outputs from LLMs by combining pydantic schemas with provider-native function calling.
Instructor is the open-source pydantic-based library for structured LLM outputs with automatic retries, streaming, and support for OpenAI, Anthropic, Gemini, and 10+ other providers.
Was this helpful?
Instructor is the gold standard for structured LLM output extraction, with 3M+ monthly downloads and support for 15+ providers. Using Pydantic models for validation and automatic retry logic, it turns unreliable LLM text into guaranteed typed Python objects. Essential for any production system that needs reliable, structured responses from LLMs.
Define output structure as Pydantic models with typed fields, descriptions, and validators. Instructor converts these to function-calling schemas and returns validated Python objects automatically.
When Pydantic validation fails, Instructor provides specific error messages to the LLM and retries. Models receive context about validation failures and can self-correct, achieving 99%+ success rates.
Unified from_provider() interface works with OpenAI, Anthropic, Google, Cohere, Mistral, DeepSeek, Ollama, and 10+ more providers. Switch providers without code changes for easy A/B testing and cost optimization.
Get incremental Pydantic model updates as the LLM generates tokens. Fields populate progressively, enabling real-time UIs that show structured data appearing as extraction progresses.
TOOLS mode uses native function calling for maximum reliability, JSON mode forces JSON output for weaker models, MD_JSON extracts from markdown blocks, and PARALLEL extracts multiple objects simultaneously.
Use Union types to let the LLM select the appropriate Pydantic model for classification tasks. Supports discriminated unions and automatic routing based on input content analysis.
Free (MIT)
Ready to get started with Instructor?
View Pricing Options →Instructor works with these platforms and services:
We believe in transparent reviews. Here's what Instructor doesn't handle well:
Weekly insights on the latest AI tools, features, and trends delivered to your inbox.
Instructor has continued expanding beyond Python in 2025 and into 2026, with official ports for TypeScript, Go, Elixir, PHP, and Ruby reaching broader provider coverage. The Python library has standardized on a from_provider entry point that unifies client instantiation across OpenAI, Anthropic, Gemini, Mistral, Cohere, Groq, Together, Fireworks, Ollama, and vLLM, and has added first-class support for newer provider features such as OpenAI Structured Outputs, Anthropic tool use refinements, and Gemini's structured generation modes. The documentation has been reorganized around a learning track, integrations catalog, cookbook, and concepts guide, and the hooks API has matured into the recommended path for observability and tracing integrations.
Developer Framework
PydanticAI is an AI-powered developer framework tool for building custom ai agents and structured output and tool calling.
AI Agent Builders
Grammar-constrained generation for deterministic model outputs.
No reviews yet. Be the first to share your experience!
Get started with Instructor and see if it's the right fit for your needs.
Get Started →Take our 60-second quiz to get personalized tool recommendations
Find Your Perfect AI Stack →Explore 20 ready-to-deploy AI agent templates for sales, support, dev, research, and operations.
Browse Agent Templates →