{"name":"Instructor: Structured Outputs for LLMs with Pydantic and Python","description":"Instructor is a powerful Python library that simplifies extracting structured data from Large Language Models (LLMs). It integrates Pydantic for robust validation, type safety, and IDE support, eliminating the need for manual JSON parsing, error handling, and retries. This tool provides a streamlined and reliable way to get structured outputs from any LLM.","github":"https://github.com/567-labs/instructor","url":"https://osrepos.com/repo/567-labs-instructor","source":"osrepos.com","sourceDescription":"This repository profile is provided by osrepos.com, an open source repository discovery platform.","repositoryProfile":"https://osrepos.com/repo/567-labs-instructor","generatedFor":"open source discovery and AI-assisted research","markdown":"https://osrepos.com/repo/567-labs-instructor.md","json":"https://osrepos.com/repo/567-labs-instructor.json","topics":["Python","LLMs","OpenAI","Pydantic","Structured Data","AI","Validation","Function Calling"],"keywords":["Python","LLMs","OpenAI","Pydantic","Structured Data","AI","Validation","Function Calling"],"stars":null,"summary":"Instructor is a powerful Python library that simplifies extracting structured data from Large Language Models (LLMs). It integrates Pydantic for robust validation, type safety, and IDE support, eliminating the need for manual JSON parsing, error handling, and retries. This tool provides a streamlined and reliable way to get structured outputs from any LLM.","content":"## Introduction\n\nInstructor is a powerful Python library designed to simplify the process of extracting structured data from Large Language Models (LLMs). It leverages Pydantic to provide robust validation, type safety, and excellent IDE support, making it easier to get reliable JSON outputs from any LLM. This tool eliminates the need for manual JSON parsing, error handling, and retries, streamlining LLM integration into your applications.\n\n## Installation\n\nGetting started with Instructor is straightforward. You can install it using pip:\n\nbash\npip install instructor\n\n\nFor other package managers, you can use:\n\nbash\nuv add instructor\npoetry add instructor\n\n\n## Examples\n\nInstructor allows you to define your desired output structure using Pydantic models and then extract that structure directly from natural language. Here's a basic example:\n\npython\nimport instructor\nfrom pydantic import BaseModel\n\n# Define what you want\nclass User(BaseModel):\n    name: str\n    age: int\n\n# Extract it from natural language\nclient = instructor.from_provider(\"openai/gpt-4o-mini\")\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"John is 25 years old\"}],\n)\n\nprint(user) # User(name='John', age=25)\n\n\nInstructor also supports advanced features like automatic retries for failed validations, streaming partial objects, and extracting complex nested data structures, making it suitable for production environments.\n\n## Why Use Instructor?\n\nInstructor addresses common challenges in working with LLMs by offering several key advantages:\n\n*   **Simplified LLM Interactions**: It abstracts away the complexity of writing intricate JSON schemas, handling validation errors, managing retries, and parsing unstructured responses.\n*   **Pydantic Integration**: By building on Pydantic, Instructor provides out-of-the-box type safety, data validation, and enhanced developer experience with IDE support.\n*   **Provider Agnostic**: Use the same simple API across various LLM providers, including OpenAI, Anthropic, Google, and local models like Ollama.\n*   **Production-Ready Features**: Includes automatic retries with error feedback for validation failures and streaming support for partial object generation, ensuring robust applications.\n*   **Battle-Tested**: Trusted by over 100,000 developers and companies, with millions of monthly downloads and thousands of GitHub stars, proving its reliability in real-world scenarios.\n\nCompared to alternatives:\n*   **vs Raw JSON mode**: Instructor offers automatic validation, retries, streaming, and nested object support without manual schema writing.\n*   **vs LangChain/LlamaIndex**: Instructor is a lighter, faster, and more focused solution specifically for structured extraction.\n*   **vs Custom solutions**: It's a battle-tested library that handles edge cases and provides a robust foundation for your AI applications.\n\n## Links\n\nExplore Instructor further with these official resources:\n\n*   [GitHub Repository](https://github.com/567-labs/instructor){:target=\"_blank\"}\n*   [Official Documentation](https://python.useinstructor.com){:target=\"_blank\"}\n*   [PyPI Package](https://pypi.org/project/instructor/){:target=\"_blank\"}\n*   [Discord Community](https://discord.gg/bD9YE9JArw){:target=\"_blank\"}\n*   [Twitter](https://twitter.com/jxnlco){:target=\"_blank\"}","metrics":{"detailViews":7,"githubClicks":5},"dates":{"published":null,"modified":"2025-10-12T18:31:22.000Z"}}