A Python framework that adds input and output guards to LLM applications and generates validated structured data from LLM outputs.
567-labs/instructor
A Python library that gets structured, Pydantic-validated data from LLMs across multiple providers, with automatic retries on validation failure.
- Stars
- 14,046
- Forks
- 1,330
- Open issues
- 214
- Last commit
- yesterday
What is it?
Instructor extracts typed data from LLM responses by letting you define the desired output as a Pydantic model. Instead of hand-writing JSON schemas and parsing raw text, you pass a response_model to the client and receive a validated Python object back.
The library wraps the APIs of several providers, including OpenAI, Anthropic, Google, Ollama and Groq, behind a single interface created with from_provider. When validation fails, Instructor sends the error message back to the model and retries, up to a configurable max_retries. It also supports streaming partial objects and nested models.
Besides Python, the project's documentation lists TypeScript, Ruby, Go, Elixir and Rust implementations.
Key features
- 01Defines output schemas with Pydantic models and returns validated objects.
- 02Works with multiple LLM providers through one from_provider interface.
- 03Retries failed validations automatically, feeding the error back to the model.
- 04Streams partial objects as they are generated.
- 05Supports nested models and lists of models.
Use cases
- Extracting fields such as names, dates or prices from free-form text.
- Turning LLM outputs into typed data for downstream application code.
- Building pipelines that need reliable JSON from models without manual parsing.
Quick start
- 1
Install the library with pip
pip install instructor - 2
Create a client for your provider and extract a Pydantic model
Things to know
- Requires an API key or a running LLM provider such as OpenAI, Anthropic, or a local Ollama server.
Topics
FAQ
- What is instructor?
- A Python library that gets structured, Pydantic-validated data from LLMs across multiple providers, with automatic retries on validation failure. Instructor extracts typed data from LLM responses by letting you define the desired output as a Pydantic model. Instead of hand-writing JSON schemas and parsing raw text, you pass a response_model to the client and receive a validated Python object back.
- Is instructor free to use? What license does it have?
- instructor is open source under the MIT license. Check the license terms before using it in commercial products.
- Is instructor still maintained?
- Actively maintained. The last commit to instructor was on Oct 20, 2026.
- What can I use instructor for?
- Extracting fields such as names, dates or prices from free-form text. Turning LLM outputs into typed data for downstream application code. Building pipelines that need reliable JSON from models without manual parsing.
- How do I install instructor?
- Install the library with pip: pip install instructor Create a client for your provider and extract a Pydantic model
- Where can I get instructor?
- The source code and installation instructions are on GitHub: https://github.com/567-labs/instructor
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A fast Python serialization and validation library that encodes and decodes JSON, MessagePack, YAML, and TOML using standard type annotations.
SQLModel is a Python library for working with SQL databases using Python classes, built on Pydantic and SQLAlchemy and designed to pair with FastAPI.
A Python library that constrains LLM outputs during generation so they match a given type, regex, JSON schema, or grammar.
A compact, human-readable encoding of JSON data designed to reduce token usage when passing structured data to LLM prompts.
A Python framework for building LLM-powered applications and agents, with standard interfaces for models, embeddings, vector stores and third-party integrations.