instructor

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Getting reliable, structured data out of LLM responses is error-prone: raw JSON parsing breaks on malformed output, and there is no built-in way to validate types or recover from bad generations. This Skill uses the Instructor library to bind LLM outputs to Pydantic models, automatically validating fields and retrying failed extractions with error feedback. ## Core Features & Use Cases - Schema-Bound Extraction: Define Pydantic response models with type hints, field constraints, enums, and nested models so LLM outputs are validated and type-safe. - Automatic Retry on Validation Failure: When output fails validation, the error is fed back to the LLM and the request retries up to a configurable limit. - Streaming Partial Results: Stream partial objects or iterable items as the model 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, headcount) from unstructured text into a validated CompanyInfo model, or classify support tickets into an enum of categories with a confidence score. ## Quick Start Ask the AI to extract a person's name, age, and email from a block of text into a validated Pydantic model using Instructor with your preferred LLM provider.

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 the fields you want, then pass it as response_model to an Instructor-wrapped client. Instructor parses the LLM output into your model and validates every field automatically.

Instructor vs LangChain for structured LLM outputs?

Instructor focuses on typed, validated outputs with automatic retries and streaming, using plain Pydantic models. LangChain is broader for chaining workflows but offers partial validation and no built-in retry on schema failure.

Does Instructor work with local models like Ollama?

Yes. Point an OpenAI-compatible client at the Ollama base URL (http://localhost:11434/v1) and use instructor.Mode.JSON. You can then call chat.completions.create with a response_model as usual.

What happens when LLM output fails Pydantic validation?

Instructor catches the ValidationError, sends the error message back to the LLM as feedback, and retries the request. This repeats up to max_retries (default 3) before raising the error to your code.

Can I stream partial structured results from an LLM?

Yes. Use client.messages.create_partial to stream incremental updates of a model as tokens arrive, or create_iterable to stream list items one at a time for real-time processing.