instructor

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

1|Updated Mar 12, 2026
One-click install
npx skills add https://github.com/kaminocorp/hermes-alpha-hunter --skill instructor-kaminocorp
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: instructor
Source: https://github.com/kaminocorp/hermes-alpha-hunter/tree/main/skills/mlops/inference/instructor
Command: npx skills add https://github.com/kaminocorp/hermes-alpha-hunter --skill instructor-kaminocorp

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 models return free-form text that breaks downstream parsing. 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 models with types, constraints, enums, and nested structures, and receive validated Python objects instead of raw JSON strings. - 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 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, founding year, industry, employee count) from unstructured text paragraphs into a typed CompanyInfo model, with automatic retries if any field fails validation. ## Quick Start Ask the agent to extract structured fields from a block of text into a 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?▼

Use Instructor with a Pydantic model: define a BaseModel class describing the fields you want, wrap your Anthropic or OpenAI client with instructor.from_anthropic or instructor.from_openai, and pass the model as response_model. The response is returned as a validated Python object.

How does Instructor handle invalid LLM output?▼

Instructor validates the LLM output against your Pydantic schema and automatically retries when validation fails. The validation error message is sent back to the LLM so it can correct its output, repeating up to the max_retries limit (default 3).

Does Instructor work with local models like Ollama?▼

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

Instructor vs LangChain for structured output?▼

Instructor provides full type safety, automatic Pydantic validation, automatic retries, and streaming of partial objects, while LangChain offers only partial type safety and no built-in validation retries. LangChain suits complex chain orchestration; Instructor suits structured extraction.

Can I stream partial structured results from an LLM?▼

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

How do I add custom validation rules to extracted fields?▼

Use Pydantic field_validator decorators for per-field logic such as regex checks or range enforcement, and model_validator for cross-field rules like ensuring end_date is after start_date. Failed validators trigger automatic retries with your error message shown to the LLM.