explaingit

567-labs/instructor

12,954PythonAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

Instructor is a Python library that makes AI models return structured, validated data instead of raw text, define a data shape, and it handles extraction, validation, and retries automatically.

Mindmap

mindmap
  root((instructor))
    What it does
      Structured extraction
      Auto validation
      Auto retry
    Tech stack
      Python
      Pydantic
      TypeScript
      Ruby
      Go
    AI providers
      OpenAI
      Anthropic
      Google
      Groq
    Features
      Streaming results
      Nested structures
      Multi language
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Extract structured fields like user name, price, or category from AI model responses reliably without manual JSON parsing.

USE CASE 2

Build AI pipelines that return validated Python objects instead of raw text, with automatic retries on failures.

USE CASE 3

Stream partial structured results progressively as the AI generates them for a more responsive interface.

USE CASE 4

Connect to multiple AI providers, OpenAI, Anthropic, Google, Groq, using the same code pattern.

Tech stack

PythonPydanticTypeScriptRubyGoElixirRust

Getting it running

Difficulty · easy Time to first run · 5min

Requires an API key for your chosen AI provider (OpenAI, Anthropic, Google, or Groq).

Use freely for any purpose, including commercial use, as long as you keep the MIT copyright notice.

In plain English

Instructor is a Python library that makes it simpler to get structured, predictable data back from AI language models. Instead of receiving raw text that you then have to parse and validate, you define a data shape using Python models (from a library called Pydantic) and pass it to Instructor, which handles extracting the correct fields, validating the result, and retrying if the AI makes a mistake. The problem it solves is common when building AI applications: language models produce free-form text, but your code usually wants a specific structure, like a user name and age, or a list of products with prices. Getting that reliably means writing JSON schema definitions, parsing the response, checking for missing fields, and re-running on failures. Instructor wraps that entire process into a single clean call. The library works with most major AI providers using the same code pattern. You configure a client pointing at OpenAI, Anthropic, Google, Groq, or a locally running model, then make a single call supplying your data shape and your message. Instructor connects to the provider, applies the structured output method that provider supports, validates the result against your definition, and returns a ready-to-use Python object. Additional features include streaming partial results as they are generated (so your interface can update progressively), extracting nested or list-type structures, and setting a retry count so that invalid responses are automatically sent back to the model with error feedback. These features handle edge cases that raw JSON mode or manual approaches tend to miss. Instructor is available for Python, TypeScript, Ruby, Go, Elixir, and Rust, each with their own documentation. The Python version is the original and most complete. The project is open source under the MIT license and reports over three million monthly downloads.

Copy-paste prompts

Prompt 1
Using instructor with Pydantic and OpenAI, write Python code to extract a list of products with name, price, and category from a customer support message.
Prompt 2
I want instructor to retry up to 3 times if Anthropic Claude returns invalid structured output. Show me how to configure the client and define the Pydantic model.
Prompt 3
Using instructor's streaming mode, show me how to progressively display user profile fields (name, email, bio) in the terminal as Claude generates them.
Prompt 4
How do I use instructor to extract a nested structure, a company object containing a list of employees, each with a name, role, and start date?
Open on GitHub → Explain another repo

← 567-labs on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.