Pydantic response models
Define the fields, types, constraints, and nested structures expected from an LLM response.
Instructor is a developer library for extracting structured, validated data from large language models. It uses Pydantic schemas, automatic retries, streaming, and a consistent interface across cloud, local, and routed LLM providers.
Instructor is a developer library for turning LLM responses into structured, typed data. Developers define the expected output with Pydantic models, then pass that model to a client request. Instructor converts the model into a schema the provider can use, validates the response, retries when validation fails, and returns a typed Pydantic object.
It is designed for schema-first extraction rather than agent orchestration. The Python workflow supports nested models, lists, enums, optional fields, field constraints, custom validators, asynchronous clients, partial responses, streaming, hooks, and access to raw completions. It can be used with hosted models, routing services, and local open-source models through documented integrations.
Define the fields, types, constraints, and nested structures expected from an LLM response.
Instructor validates generated data against the response model and can retry failed requests, with retry behavior configurable through max_retries and Tenacity.
from_provider provides a common client-initialization pattern across supported providers, while provider-specific modes and capabilities remain documented separately.
create_partial can yield partially populated models as a response is generated, and the library supports streaming lists and iterable responses.
Depending on provider support, Instructor can use tool calls, JSON generation, JSON Schema, Markdown-embedded JSON, or parallel tool calls.
The Python client supports ordinary calls and an asynchronous client through async_client=True.
Convert a sentence, document fragment, or user message into a typed object such as a person record with fields for name, age, and occupation.
Represent a customer support case with customer details and a validated list of tickets, including priorities, estimated hours, and field-level rules.
Consume partial model results while a large structured response is being generated instead of waiting for the complete object.
Use an Instructor client inside a FastAPI route so submitted text is returned as a declared Pydantic response type.
Keep the response-model workflow while moving between cloud providers, routing layers, or local models such as those served through Ollama.
Install the base package with `pip install instructor`. Provider-specific extras are available for integrations such as Anthropic and Google/Gemini.
You provide a Pydantic class as `response_model`. Instructor converts that model into a provider-compatible schema, formats the request, validates the response, retries on validation failure, and returns the typed object.
Yes. The documentation describes local open-source model integrations through Ollama and llama-cpp-python, as well as other provider and routing integrations. Capabilities vary by provider.
Yes. `create_with_completion` returns both the parsed Pydantic result and the raw completion.
Yes. Initialize a provider with `async_client=True` and await the client’s `create` call. The documentation also provides a FastAPI example using an asynchronous endpoint.
upstage.ai
Upstage AI offers document processing and large language models for converting complex files, extracting structured data, and automating workflows via API, Studio, AWS Marketplace, or on-prem deployment.
microsoft.github.io
GraphRAG is a research project and data pipeline for extracting structured information from unstructured text with language models, then using graph-based context to support question answering over private data.
file.ai
fileAI turns unstructured files into structured, validated data and automated workflows for enterprise teams.
www.diffbot.com
Diffbot transforms unstructured public web content into structured data for AI applications. Its APIs and agent skills support web search, page extraction, crawling, entity resolution, natural-language processing, and Knowledge Graph research.
you.com
You.com provides developer APIs for web search, content extraction, and cited research across web, news, and finance workflows for AI agents and RAG systems.
landing.ai
Document processing APIs for developers building structured, traceable data pipelines.