instructor

Extract structured, validated data from LLM responses using Pydantic models with automatic retries.

14|5|Updated Apr 9, 2026
One-click install
npx skills add https://github.com/MLT-OSS/hermes-agent-go --skill instructor-mlt-oss
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: instructor
Source: https://github.com/MLT-OSS/hermes-agent-go/tree/main/optional-skills/mlops/instructor
Command: npx skills add https://github.com/MLT-OSS/hermes-agent-go --skill instructor-mlt-oss

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, fields go missing, and types are inconsistent. This Skill uses the Instructor library to enforce 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 custom validators; the LLM output is parsed and validated against them automatically. - Automatic Retries: When validation fails, the error message is sent back to the LLM and extraction is retried up to a configurable limit. - Streaming & Multi-Provider Support: Stream partial objects or iterables in real time, and work with Anthropic Claude, OpenAI, or local models via Ollama. - Use Case: Extract company information (name, founding year, industry, headcount) from unstructured text into a typed CompanyInfo model, or classify articles into fixed categories with confidence scores. ## Quick Start Use the instructor skill to extract a person's name, age, and email from a block of text into a validated Pydantic model.

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 BaseModel defining your output schema, then pass it as response_model to client.messages.create or client.chat.completions.create. The library parses and validates the LLM output against your model automatically.

How does Instructor handle invalid LLM outputs?

Instructor validates outputs with Pydantic and automatically retries when validation fails, sending the error message back to the LLM for correction. The max_retries parameter controls attempts, defaulting to 3.

Does Instructor work with local models like Ollama?

Yes. Point the OpenAI client at the Ollama base URL (http://localhost:11434/v1) and use instructor.Mode.JSON. You can then use models like llama3.1 with the same response_model interface.

Instructor vs LangChain for structured outputs?

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

Can I stream partial structured results from an LLM?

Yes. Use client.messages.create_partial to stream incremental updates of a model as it generates, or create_iterable to receive list items one at a time for real-time UI updates.

How do I add custom validation rules to extracted fields?

Use Pydantic field_validator decorators for per-field logic like regex checks or range enforcement, and model_validator for cross-field rules such as ensuring end_date follows start_date. Failed validators trigger automatic retries.