{"id":27896291,"url":"https://github.com/567-labs/instructor","last_synced_at":"2026-02-24T05:01:33.732Z","repository":{"id":175256690,"uuid":"653589102","full_name":"567-labs/instructor","owner":"567-labs","description":"structured outputs for llms ","archived":false,"fork":false,"pushed_at":"2025-05-12T22:06:57.000Z","size":134280,"stargazers_count":10405,"open_issues_count":23,"forks_count":781,"subscribers_count":57,"default_branch":"main","last_synced_at":"2025-05-12T22:44:05.188Z","etag":null,"topics":["openai","openai-function-calli","openai-functions","pydantic-v2","python","validation"],"latest_commit_sha":null,"homepage":"https://python.useinstructor.com/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/567-labs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"jxnl"}},"created_at":"2023-06-14T10:42:23.000Z","updated_at":"2025-05-12T21:36:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"d9e6f296-3c4a-45dc-8ae3-de26f56fe1c9","html_url":"https://github.com/567-labs/instructor","commit_stats":null,"previous_names":["jxnl/openai_function_call","instructor-ai/instructor","567-labs/instructor"],"tags_count":88,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/567-labs%2Finstructor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/567-labs%2Finstructor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/567-labs%2Finstructor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/567-labs%2Finstructor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/567-labs","download_url":"https://codeload.github.com/567-labs/instructor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253843196,"owners_count":21972872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["openai","openai-function-calli","openai-functions","pydantic-v2","python","validation"],"created_at":"2025-05-05T16:13:32.228Z","updated_at":"2026-01-16T07:58:57.264Z","avatar_url":"https://github.com/567-labs.png","language":"Python","readme":"# Instructor: Structured Outputs for LLMs\n\nGet reliable JSON from any LLM. Built on Pydantic for validation, type safety, and IDE support.\n\n```python\nimport instructor\nfrom pydantic import BaseModel\n\n\n# Define what you want\nclass User(BaseModel):\n    name: str\n    age: int\n\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\n**That's it.** No JSON parsing, no error handling, no retries. Just define a model and get structured data.\n\n[![PyPI](https://img.shields.io/pypi/v/instructor?style=flat-square)](https://pypi.org/project/instructor/)\n[![Downloads](https://img.shields.io/pypi/dm/instructor?style=flat-square)](https://pypi.org/project/instructor/)\n[![GitHub Stars](https://img.shields.io/github/stars/instructor-ai/instructor?style=flat-square)](https://github.com/instructor-ai/instructor)\n[![Discord](https://img.shields.io/discord/1192334452110659664?style=flat-square)](https://discord.gg/bD9YE9JArw)\n[![Twitter](https://img.shields.io/twitter/follow/jxnlco?style=flat-square)](https://twitter.com/jxnlco)\n\n\u003e **Use Instructor for fast extraction, reach for PydanticAI when you need agents.** Instructor keeps schema-first flows simple and cheap. If your app needs richer agent runs, built-in observability, or shareable traces, try [PydanticAI](https://ai.pydantic.dev/). PydanticAI is the official agent runtime from the Pydantic team, adding typed tools, replayable datasets, evals, and production dashboards while using the same Pydantic models. Dive into the [PydanticAI docs](https://ai.pydantic.dev/) to see how it extends Instructor-style workflows.\n\n## Why Instructor?\n\nGetting structured data from LLMs is hard. You need to:\n\n1. Write complex JSON schemas\n2. Handle validation errors  \n3. Retry failed extractions\n4. Parse unstructured responses\n5. Deal with different provider APIs\n\n**Instructor handles all of this with one simple interface:**\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003cb\u003eWithout Instructor\u003c/b\u003e\u003c/td\u003e\n\u003ctd\u003e\u003cb\u003eWith Instructor\u003c/b\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```python\nresponse = openai.chat.completions.create(\n    model=\"gpt-4\",\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n    tools=[\n        {\n            \"type\": \"function\",\n            \"function\": {\n                \"name\": \"extract_user\",\n                \"parameters\": {\n                    \"type\": \"object\",\n                    \"properties\": {\n                        \"name\": {\"type\": \"string\"},\n                        \"age\": {\"type\": \"integer\"},\n                    },\n                },\n            },\n        }\n    ],\n)\n\n# Parse response\ntool_call = response.choices[0].message.tool_calls[0]\nuser_data = json.loads(tool_call.function.arguments)\n\n# Validate manually\nif \"name\" not in user_data:\n    # Handle error...\n    pass\n```\n\n\u003c/td\u003e\n\u003ctd\u003e\n\n```python\nclient = instructor.from_provider(\"openai/gpt-4\")\n\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n\n# That's it! user is validated and typed\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n## Install in seconds\n\n```bash\npip install instructor\n```\n\nOr with your package manager:\n```bash\nuv add instructor\npoetry add instructor\n```\n\n## Works with every major provider\n\nUse the same code with any LLM provider:\n\n```python\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# With API keys directly (no environment variables needed)\nclient = instructor.from_provider(\"openai/gpt-4o\", api_key=\"sk-...\")\nclient = instructor.from_provider(\"anthropic/claude-3-5-sonnet\", api_key=\"sk-ant-...\")\nclient = instructor.from_provider(\"groq/llama-3.1-8b-instant\", api_key=\"gsk_...\")\n\n# All use the same API!\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n## Production-ready features\n\n### Automatic retries\n\nFailed validations are automatically retried with the error message:\n\n```python\nfrom pydantic import BaseModel, field_validator\n\n\nclass User(BaseModel):\n    name: str\n    age: int\n\n    @field_validator('age')\n    def validate_age(cls, v):\n        if v \u003c 0:\n            raise ValueError('Age must be positive')\n        return v\n\n\n# Instructor automatically retries when validation fails\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n    max_retries=3,\n)\n```\n\n### Streaming support\n\nStream partial objects as they're generated:\n\n```python\nfrom instructor import Partial\n\nfor partial_user in client.chat.completions.create(\n    response_model=Partial[User],\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n    stream=True,\n):\n    print(partial_user)\n    # User(name=None, age=None)\n    # User(name=\"John\", age=None)\n    # User(name=\"John\", age=25)\n```\n\n### Nested objects\n\nExtract complex, nested data structures:\n\n```python\nfrom typing import List\n\n\nclass Address(BaseModel):\n    street: str\n    city: str\n    country: str\n\n\nclass User(BaseModel):\n    name: str\n    age: int\n    addresses: List[Address]\n\n\n# Instructor handles nested objects automatically\nuser = client.chat.completions.create(\n    response_model=User,\n    messages=[{\"role\": \"user\", \"content\": \"...\"}],\n)\n```\n\n## Used in production by\n\nTrusted by over 100,000 developers and companies building AI applications:\n\n- **3M+ monthly downloads**\n- **10K+ GitHub stars**  \n- **1000+ community contributors**\n\nCompanies using Instructor include teams at OpenAI, Google, Microsoft, AWS, and many YC startups.\n\n## Get started\n\n### Basic extraction\n\nExtract structured data from any text:\n\n```python\nfrom pydantic import BaseModel\nimport instructor\n\nclient = instructor.from_provider(\"openai/gpt-4o-mini\")\n\n\nclass Product(BaseModel):\n    name: str\n    price: float\n    in_stock: bool\n\n\nproduct = client.chat.completions.create(\n    response_model=Product,\n    messages=[{\"role\": \"user\", \"content\": \"iPhone 15 Pro, $999, available now\"}],\n)\n\nprint(product)\n# Product(name='iPhone 15 Pro', price=999.0, in_stock=True)\n```\n\n### Multiple languages\n\nInstructor's simple API is available in many languages:\n\n- [Python](https://python.useinstructor.com) - The original\n- [TypeScript](https://js.useinstructor.com) - Full TypeScript support\n- [Ruby](https://ruby.useinstructor.com) - Ruby implementation  \n- [Go](https://go.useinstructor.com) - Go implementation\n- [Elixir](https://hex.pm/packages/instructor) - Elixir implementation\n- [Rust](https://rust.useinstructor.com) - Rust implementation\n\n### Learn more\n\n- [Documentation](https://python.useinstructor.com) - Comprehensive guides\n- [Examples](https://python.useinstructor.com/examples/) - Copy-paste recipes  \n- [Blog](https://python.useinstructor.com/blog/) - Tutorials and best practices\n- [Discord](https://discord.gg/bD9YE9JArw) - Get help from the community\n\n## Why use Instructor over alternatives?\n\n**vs Raw JSON mode**: Instructor provides automatic validation, retries, streaming, and nested object support. No manual schema writing.\n\n**vs LangChain/LlamaIndex**: Instructor is focused on one thing - structured extraction. It's lighter, faster, and easier to debug.\n\n**vs Custom solutions**: Battle-tested by thousands of developers. Handles edge cases you haven't thought of yet.\n\n## Contributing\n\nWe welcome contributions! Check out our [good first issues](https://github.com/instructor-ai/instructor/labels/good%20first%20issue) to get started.\n\n## License\n\nMIT License - see [LICENSE](https://github.com/instructor-ai/instructor/blob/main/LICENSE) for details.\n\n---\n\n\u003cp align=\"center\"\u003e\nBuilt by the Instructor community. Special thanks to \u003ca href=\"https://twitter.com/jxnlco\"\u003eJason Liu\u003c/a\u003e and all \u003ca href=\"https://github.com/instructor-ai/instructor/graphs/contributors\"\u003econtributors\u003c/a\u003e.\n\u003c/p\u003e","funding_links":["https://github.com/sponsors/jxnl"],"categories":["Python","AI and Agents","Agent Integration \u0026 Deployment Tools","LLM","NLP","Machine Learning"],"sub_categories":["LLM Framework Tools"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F567-labs%2Finstructor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F567-labs%2Finstructor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F567-labs%2Finstructor/lists"}