Discover and explore top open-source AI tools and projects—updated daily.
567-labsSDK for structured LLM outputs using Pydantic models
Top 4.3% on SourcePulse
Instructor is a Python library designed to simplify obtaining structured outputs from Large Language Models (LLMs). It targets developers building LLM-powered applications, enabling them to define Pydantic models for desired outputs, handle retries, validate responses, and stream results, thereby streamlining LLM integration and improving output reliability.
How It Works
Instructor leverages Pydantic models to define the schema for LLM outputs. It patches LLM client libraries (like OpenAI's) to inject instructions for the LLM to return JSON conforming to the specified Pydantic model. This approach ensures data validation and type safety, abstracting away the complexities of prompt engineering for structured data extraction.
Quick Start & Requirements
pip install -U instructorHighlighted Details
Maintenance & Community
uv for faster dependency management.ruff for formatting/linting and pyright for type checking.Licensing & Compatibility
Limitations & Caveats
The library's core functionality relies on patching LLM client libraries, which could be subject to breaking changes in upstream provider SDKs. While it supports numerous providers, the quality of structured output generation may vary depending on the underlying LLM's capabilities and the specific provider's tool-calling implementation.
16 hours ago
1 day
kagisearch
pydantic