{"name":"Instructor: Structured Outputs for LLMs with Pydantic and Python","description":"Instructor is a powerful Python library designed to simplify obtaining structured outputs from Large Language Models (LLMs). By leveraging Pydantic, it provides robust validation, type safety, and IDE support, eliminating the need for manual JSON parsing, error handling, or retries. This tool streamlines the process of extracting reliable, structured data from any LLM provider.","github":"https://github.com/instructor-ai/instructor","url":"https://osrepos.com/repo/instructor-ai-instructor","source":"osrepos.com","sourceDescription":"This repository profile is provided by osrepos.com, an open source repository discovery platform.","repositoryProfile":"https://osrepos.com/repo/instructor-ai-instructor","generatedFor":"open source discovery and AI-assisted research","markdown":"https://osrepos.com/repo/instructor-ai-instructor.md","json":"https://osrepos.com/repo/instructor-ai-instructor.json","topics":["Python","LLM Tools","AI","OpenAI","Pydantic","Structured Data","Validation","Function Calling"],"keywords":["Python","LLM Tools","AI","OpenAI","Pydantic","Structured Data","Validation","Function Calling"],"stars":null,"summary":"Instructor is a powerful Python library designed to simplify obtaining structured outputs from Large Language Models (LLMs). By leveraging Pydantic, it provides robust validation, type safety, and IDE support, eliminating the need for manual JSON parsing, error handling, or retries. This tool streamlines the process of extracting reliable, structured data from any LLM provider.","content":"## Introduction\nInstructor is a Python library that revolutionizes how developers interact with Large Language Models (LLMs) to obtain structured data. It addresses the common challenges of getting reliable, validated JSON outputs from LLMs by integrating seamlessly with Pydantic. This integration provides automatic validation, type safety, and excellent IDE support, significantly simplifying the development of AI applications. Instructor handles complex tasks such as writing JSON schemas, managing validation errors, retrying failed extractions, and parsing unstructured responses across various LLM providers, all through a single, intuitive interface.\n\n## Installation\nGetting started with Instructor is straightforward. You can install it using pip:\n\nbash\npip install instructor\n\n\nAlternatively, you can use other package managers like `uv` or `poetry`:\n\nbash\nuv add instructor\npoetry add instructor\n\n\n## Examples\nInstructor's core strength lies in its simplicity. Define your desired output structure using a Pydantic `BaseModel`, and Instructor handles the rest. Below is a basic example demonstrating how to extract user information:\n\npython\nimport instructor\nfrom pydantic import BaseModel\n\nclass User(BaseModel):\n    name: str\n    age: int\n\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 a wide range of LLM providers, allowing you to use the same API for OpenAI, Anthropic, Google, Ollama, and more.\n\npython\n# OpenAI\nclient = instructor.from_provider(\"openai/gpt-4o\")\n\n# Anthropic\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\")\n\n# Google\nclient = instructor.from_provider(\"google/gemini-pro\")\n\n# Ollama (local)\nclient = instructor.from_provider(\"ollama/llama3.2\")\n\n# All use the same API!\n# user = client.chat.completions.create(\n#     response_model=User,\n#     messages=[{\"role\": \"user\", \"content\": \"Extract a user from this text...\"}],\n# )\n\n\n## Why use Instructor\nInstructor stands out by offering a comprehensive solution for structured LLM outputs, addressing many pain points developers face:\n\n*   **Automatic Validation and Retries**: It automatically validates outputs against your Pydantic models and retries if validation fails, providing robust error handling.\n*   **Type Safety and IDE Support**: Leveraging Pydantic ensures strong typing and excellent IDE integration, making your code more maintainable and less prone to errors.\n*   **Provider Agnostic**: Use the same clean API across various LLM providers, including OpenAI, Anthropic, Google, and local models like Ollama.\n*   **Streaming Support**: Stream partial objects as they are generated, enabling real-time feedback and more dynamic applications.\n*   **Complex Data Structures**: Easily extract nested objects and lists, simplifying the handling of intricate data models.\n*   **Simplified Development**: Eliminates the need for manual JSON schema writing, parsing, and error handling, allowing you to focus on application logic.\n\n## Links\nTo learn more and get started with Instructor, explore these official resources:\n\n*   [Documentation](https://python.useinstructor.com){:target=\"_blank\"}\n*   [Examples](https://python.useinstructor.com/examples/){:target=\"_blank\"}\n*   [Blog](https://python.useinstructor.com/blog/){:target=\"_blank\"}\n*   [Discord Community](https://discord.gg/bD9YE9JArw){:target=\"_blank\"}\n*   [GitHub Repository](https://github.com/567-labs/instructor){:target=\"_blank\"}","metrics":{"detailViews":8,"githubClicks":6},"dates":{"published":null,"modified":"2025-11-08T20:00:44.000Z"}}