Instructor logo

Instructor

Free

Most widely used library for structured LLM outputs — typed extraction from any model, 3M+ monthly downloads

FreeFree tier
Type
Open Source

About Instructor

Instructor is a Python library that simplifies obtaining structured JSON outputs from large language models (LLMs) by leveraging Pydantic for schema definition, validation, and type safety. Instead of manually crafting JSON schemas, handling parsing errors, and retrying failed extractions, developers define a Pydantic model and call client.chat.completions.create(response_model=...) to get validated, typed data directly. It supports multiple LLM providers (e.g., OpenAI, Anthropic) through a unified interface, handling all the boilerplate and error handling automatically. With over 3 million monthly downloads, Instructor is the most widely used library for structured LLM outputs.

Key Features

Define output schema using Pydantic models (BaseModel)
Automatic validation and type safety of LLM responses
Built-in retry logic for failed extractions
No manual JSON parsing or error handling needed
Single-function call to get structured data: `client.chat.completions.create(response_model=...)`
Support for multiple LLM providers via `instructor.from_provider()`
Clean separation: Instructor for extraction, PydanticAI for agents
Lightweight and fast integration

Pros & Cons

Pros
  • Eliminates complex boilerplate: no JSON schemas, no manual parsing
  • Leverages Pydantic for robust validation and IDE autocompletion
  • Works with any LLM provider through a consistent interface
  • Open source and free to use (MIT license)
  • Large community with 13.6k+ GitHub stars and 1.2k forks
  • Reduces development time for extraction tasks
Cons
  • Primarily focused on extraction; not designed for multi-step agent workflows
  • Requires Python and Pydantic as a dependency
  • May introduce overhead for simple one-off prompts
  • Limited to cases where output can be modeled with Pydantic schemas

Best For

Extract structured data (e.g., user profiles, events) from natural languageBuild typed API responses from LLM outputs for backend systemsSimplify data validation pipelines when processing LLM-generated textAutomate form filling or data entry by converting free text to structured recordsCreate reproducible datasets by reliably parsing LLM outputs into consistent formats

FAQ

What is Instructor?
Instructor is a Python library that lets you define Pydantic models and get structured JSON outputs from any LLM without manual parsing, validation, or retry logic.
How does Instructor differ from PydanticAI?
Instructor is optimized for fast, schema-first extraction. PydanticAI is the official agent runtime from the Pydantic team, adding typed tools, replayable datasets, evals, and production dashboards for richer agent runs.
Which LLM providers does Instructor support?
Instructor supports multiple providers including OpenAI, Anthropic, and others via the `from_provider()` method.
Is Instructor free to use?
Yes, Instructor is open source and available under the MIT license. You can install it via pip (`pip install instructor`) or other package managers.
Do I need to handle errors or retries manually?
No. Instructor automatically handles validation errors and retries failed extractions, returning validated, typed data.