instructor
structured outputs for llm
What it is and what it does
Instructor is a Python library that bridges Pydantic models and LLM APIs to extract structured, validated data from natural language. Instead of writing JSON schemas, parsing responses, and handling validation errors manually, you define a Pydantic model and pass it to Instructor; the library generates the schema, sends it to the LLM, validates the response, and automatically retries on validation failure. It works with OpenAI, Anthropic, Google, Ollama, Groq, and other providers through a unified interface.
The package is built on Pydantic for type safety and IDE support, includes automatic retries with error feedback, supports streaming partial objects, handles nested data structures, and eliminates boilerplate around JSON parsing and manual validation. It's designed for developers who need reliable structured extraction without the complexity of writing custom parsing logic or managing provider-specific APIs.
Use it for:
- Extract product details (name, price, availability) from unstructured product descriptions or web scrapes.
- Parse customer feedback into structured fields (sentiment, category, action items) for downstream processing.
- Convert natural language requirements into typed configuration objects for application setup.
- Batch-extract entities (people, places, organizations) from documents with automatic validation and retry.
- Build chatbot intents and slot-filling workflows where LLM responses must conform to a known schema.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Instructor wraps LLM APIs to extract validated, typed structured data from natural language by defining Pydantic models and letting the package handle schema generation, validation, and retries.
Yes. Instructor is actively maintained, has no known vulnerabilities, low install friction, and a permissive license. It solves a real problem—reliable structured extraction from LLMs—with a clean API and broad provider support. Install it if you need to extract validated structured data from LLM responses; skip it if you're building agents or need richer observability (the docs suggest PydanticAI for that).
Install
instructor on PyPI
pip
pip install instructoruv
uv add instructorpoetry
poetry add instructorInstalling instructor
Before you install
Low friction: pure Python wheel with no compiled dependencies. Active maintenance—last commit 2026-08-09, 47 days since latest release. Eleven runtime dependencies (aiohttp, pydantic, openai, requests, tenacity, etc.) are all stable, widely-used libraries.
License in practice
MIT license is permissive; you can use, modify, and distribute this package freely in commercial and private projects without restriction.
Quickstart
pip install instructor
import instructor
from pydantic import BaseModel
class User(BaseModel):
name: str
age: int
client = instructor.from_provider("openai/gpt-4o-mini")
user = client.chat.completions.create(
response_model=User,
messages=[{"role": "user", "content": "John is 25 years old"}],
)
print(user)
Requires Python 3.9 or later. You must have an API key for at least one supported LLM provider (OpenAI, Anthropic, Google, Ollama, Groq, etc.) and set it as an environment variable or pass it explicitly.
Verify before relying
- Whether all 11 runtime dependencies are truly required for basic use or if some are optional for specific providers.
- Performance characteristics (latency, token efficiency) compared to raw LLM API calls or alternative extraction libraries.
- Coverage and reliability of validation retries across different LLM providers and edge cases.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4.0,>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 11 — aiohttp, docstring-parser, jinja2, jiter, openai, pydantic-core, pydantic, requests, rich, tenacity, typer |
| Maintenance | actively maintained — 47 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 19,880,373/month — #1,053 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: instructor-1.15.4-py3-none-any.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
langextractLangExtract uses LLMs to extract and ground…
permissive · top 15,000 on PyPI
outlinesOutlines constrains LLM generation to produce…
permissive · top 5,000 on PyPI
pydantic-aiPydantic AI is a Python framework for building…
permissive · top 5,000 on PyPI
pydantic-handlebarsRenders Handlebars templates for composing LLM…
permissive · top 5,000 on PyPI
trustcallTrustcall helps LLMs reliably generate and…
permissive · top 5,000 on PyPI
vlmrun-hubProvides a catalog of pre-defined Pydantic…
permissive · top 15,000 on PyPI
landingai-adeConverts PDFs and images into structured…
permissive · top 15,000 on PyPI
langdiffLangDiff streams structured LLM outputs to…
permissive · top 15,000 on PyPI
lm-format-enforcerConstrains language model token generation to…
permissive · top 5,000 on PyPI
jsonschema-pydantic-converterConverts JSON Schema definitions to Pydantic v2…
permissive · top 15,000 on PyPI