instructor

Extract structured data from LLM responses with Pydantic validation and automatic retries.

Updated Jun 7, 2026
One-click install
npx skills add https://github.com/Chensihakniroth/ANAKOT-AGENT --skill instructor-chensihakniroth
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: instructor
Source: https://github.com/Chensihakniroth/ANAKOT-AGENT/tree/main/optional-skills/mlops/instructor
Command: npx skills add https://github.com/Chensihakniroth/ANAKOT-AGENT --skill instructor-chensihakniroth

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires instructor, pydantic, openai, anthropic, and includes references (resource) components.

What problem does it solve? Getting reliable, structured data from LLM responses is difficult because raw text outputs are unpredictable and hard to parse. This Skill solves that by enforcing Pydantic schemas on LLM outputs, automatically validating results, and retrying failed extractions with error feedback. ## Core Features & Use Cases - Schema-Validated Extraction: Define Pydantic response models with type hints, field constraints, enums, and nested models so LLM outputs always match your expected structure. - Automatic Retry on Validation Failure: When output fails validation, the error is sent back to the LLM which retries up to a configurable limit. - Streaming Partial Results: Stream partial objects or iterables as the LLM generates them for real-time UI updates. - Multi-Provider Support: Works with Anthropic Claude, OpenAI, and local models via Ollama using a consistent API. - Use Case: Extract company information (name, founded year, industry, employees) from unstructured text paragraphs into a validated CompanyInfo model, or classify articles into fixed categories with confidence scores. ## Quick Start Ask the agent to extract structured fields like name, age, and email from a block of text into a validated Pydantic model using Instructor.

Frequently Asked Questions about instructor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I extract structured data from LLM responses in Python?▼

Define a Pydantic BaseModel describing your desired output, then pass it as response_model to an Instructor-wrapped client. Instructor parses the LLM output into your model and validates it automatically, retrying if validation fails.

Instructor vs LangChain for structured LLM outputs?▼

Instructor provides full type safety, automatic Pydantic validation, automatic retries, and streaming with a low learning curve. LangChain offers partial type safety and no built-in validation or retry, but suits complex chain orchestration better.

Does Instructor work with local models like Ollama?▼

Yes. Point an OpenAI client at the local Ollama server (http://localhost:11434/v1) and wrap it with instructor.from_openai using Mode.JSON. You can then use models like llama3.1 with response_model validation.

How does Instructor handle validation failures?▼

When Pydantic validation fails, Instructor sends the error message back to the LLM, which regenerates the output with that feedback. This repeats up to max_retries (default 3), after which a ValidationError is raised for you to handle.

Can I stream partial structured results with Instructor?▼

Yes. Use create_partial to stream incremental updates of a model as the LLM generates, or create_iterable to receive list items one at a time. This enables real-time UI updates during generation.

What validation constraints can I add to Pydantic response models?▼

You can use Field constraints like ge, le, min_length, max_length, and regex patterns, plus types like EmailStr and HttpUrl. Custom field_validator and model_validator decorators support cross-field and business-logic validation.