Instructor is a structured output tool for large language models, with the core goal of enabling developers to obtain structured data from LLMs in a simple, verifiable way.
Purpose: To solve common problems encountered when obtaining structured data from LLMs, such as writing complex JSON Schemas, handling validation errors, retrying on failure, parsing unstructured responses, and dealing with API differences across providers.
Main capabilities:
- Define the required data fields with Pydantic models; Instructor requests these fields from the LLM and validates the response.
- When validation fails, it can automatically retry with Pydantic's feedback information.
- Supports streaming output, allowing partial objects to be streamed during generation.
- Supports extraction of complex, nested data structures.
- The same code can work with multiple major LLM providers.
- Provides implementations in multiple languages: Python (the original version), TypeScript, Ruby, Go, Elixir, and Rust.
- Instructor version 1.18 adds classification and scoring capabilities through the OpenAI Decisions API and Jev, allowing decision models to be defined in Python.
Usage: Official examples show that after installing Instructor and setting OPENAI_API_KEY, the examples can be run. The installation command is pip install instructor (or use the corresponding package manager). The basic workflow is to define a Pydantic model, call the Instructor interface to request structured results from the LLM, and obtain validated data. Official resources also include documentation, examples, a blog, and a Discord community.
Use cases: Suitable for schema-first workflows that require fast, low-cost structured data extraction. Official recommendations: when agent capabilities are needed, consider PydanticAI; if the application requires richer agent execution, built-in observability, or shareable traces, PydanticAI, as the Pydantic team's official agent runtime, provides typed tools, replayable datasets, evaluation, and production dashboards, and reuses the same Pydantic models.
Limitations and notes: The official materials do not provide complete details on specific pricing, costs, or platform support scope, so these are not currently available. The project is under the MIT license.