Instructor

Python library that turns LLM replies into validated Pydantic objects, with retries and streaming.

Open SourceSelf Hosted
0.0 (0)

About

Getting typed data out of a chat model is the whole job here. You declare a Pydantic class, pass it as response_model, and the library handles schema translation, the provider call, parsing and validation; when a field fails a validator, the error text goes back to the model and the request is retried up to a limit you choose. One from_provider() entry point covers OpenAI, Anthropic, Gemini, Vertex AI, Mistral, Cohere, Groq, xAI, Bedrock and several more, plus local models through Ollama or any OpenAI-compatible server. It can stream partially filled objects as tokens arrive, copes with nested models and lists, and ships a small CLI for batch jobs, file uploads and usage. Setup is pip install instructor on Python 3.9 or newer, with pydantic 2 and the openai SDK as core dependencies; no GPU is involved because inference runs wherever your provider does. MIT licensed, so commercial use is unrestricted, and ports exist for TypeScript, Ruby, Go, Elixir and Rust. Best for developers who need dependable extraction or classification without adopting a full agent framework; the maintainers point to PydanticAI for agent-heavy work.

Should you use Instructor?

Pick it when

Pick Instructor when a Python app needs typed, validated objects from OpenAI, Anthropic, Google, Mistral, or Ollama with few new concepts: define a Pydantic model, keep the SDK you already use, and let validation errors trigger retries.

Look elsewhere when

Skip it if retries are too costly and you need generation that cannot produce invalid output, where Outlines or Guidance constrain decoding on local models. For tools, agents, and evals around the extraction, Pydantic AI goes further.

Alternatives to Instructor

  • Pydantic AI

    The same Pydantic validation inside a full agent framework with tools, dependency injection, durable execution, and evals, more to learn for plain extraction.

  • BAML

    A schema-first DSL with generated clients for Python, TypeScript, and more plus a VS Code playground, worth it for multi-language teams, overkill for one script.

  • Outlines

    Constrains decoding so local models emit valid JSON on the first pass, avoiding retry costs, but needs a backend it can control.

  • Guidance

    Grammar-constrained generation with control flow and token fast-forwarding, more power over local models but more concepts than a thin wrapper.

Reviews (0)

Leave a Review

No reviews yet. Be the first to review!

Details

Price
Free
Platform
Hybrid
Difficulty
Easy (2/5)
License
MIT
Added
Jan 29, 2026

Tags