567-labs/instructor
structured outputs for llms
What it solves
Instructor simplifies the process of getting reliable, structured data (like JSON) from Large Language Models (LLMs). It eliminates the need to manually write complex JSON schemas, handle validation errors, parse unstructured responses, or implement custom retry logic when an LLM fails to follow a schema.
How it works
It uses Pydantic models to define the desired output structure. When a request is made to an LLM, Instructor handles the schema generation and validation. If the LLM's response fails validation, Instructor can automatically retry the request, feeding the error message back to the model to correct the output. It provides a unified interface that works across multiple providers including OpenAI, Anthropic, Google, and local models via Ollama.
Who it’s for
Developers who need to extract specific data from natural language or ensure that LLM outputs strictly adhere to a predefined type-safe schema for use in production applications.
Highlights
- Pydantic Integration: Leverages Pydantic for type safety, validation, and IDE support.
- Multi-Provider Support: Works with OpenAI, Anthropic, Google, Groq, and Ollama using a consistent API.
- Automatic Retries: Automatically retries failed extractions using validation error messages.
- Streaming: Supports streaming partial objects as they are being generated.
- Nested Structures: Handles complex, nested data objects automatically.
Related
- Project
- Project
- Project
- Dispatch
- Project