Structured outputs from LLMs, validated with Pydantic
open sourceMITfree
Instructor is a Python library for getting structured data out of large language models. You describe the output you want as a Pydantic model, and Instructor sends it to the model, validates the reply against it and retries automatically when validation fails, with streaming of partial objects and lists. One interface, instructor.from_provider, works with more than 15 providers, including OpenAI, Anthropic, Google Gemini, DeepSeek and local models through Ollama, and it supports async code and hooks. Its docs point to Pydantic AI for agents and keep Instructor for schema-first extraction.
Problems it solves
- get my LLM to return valid JSON that matches a schema every time
- extract typed fields from text with an LLM in Python
- retry the model call automatically when its output fails validation
Features
- extract structured data from LLM replies into Pydantic models
- validation with automatic retries
- streaming of partial objects and lists
- one interface for 15+ providers, including local models via Ollama
- async support and hooks
- CLI that opens and searches the docs
Alternatives
The same job
These do what Instructor does.
- LangExtract Extract structured information from unstructured text using LLMs, with precise source grounding