instructor

Extract structured, Pydantic-validated outputs from LLM responses across multiple providers.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? LLM responses arrive as unstructured text that breaks downstream code when parsed manually. This Skill teaches how to use the Instructor library to force LLM outputs into typed Pydantic models, with automatic validation and retries when the model returns malformed data. ## Core Features & Use Cases - Schema-Validated Extraction: Define Pydantic response models with field constraints, enums, and custom validators so LLM outputs always match your expected structure. - Automatic Retry on Validation Failure: When output fails validation, the error is fed back to the LLM and retried up to a configurable limit. - Streaming and Multi-Provider Support: Stream partial objects or iterables in real time, and switch between Anthropic, OpenAI, and local Ollama models with a consistent API. - Use Case: Extract company name, founding year, industry, and employee count from a paragraph of text into a typed CompanyInfo object, 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 configured LLM provider.

Frequently Asked Questions about instructor

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

FAQPage Schema
How do I get structured JSON output from an LLM in Python?▼

Use Instructor to wrap your Anthropic or OpenAI client and pass a Pydantic model as response_model. The library parses the LLM output into your typed model and validates every field automatically.

How does Instructor handle invalid LLM outputs?▼

Instructor validates the response against your Pydantic schema and, on failure, sends the validation error back to the LLM for another attempt. It retries up to max_retries, which defaults to 3.

Instructor vs LangChain for structured output extraction?▼

Instructor provides full type safety, automatic Pydantic validation, retries, and streaming with a low learning curve. LangChain suits complex chain orchestration but lacks built-in validation and retry for outputs.

Can I use Instructor with local models like Ollama?▼

Yes. Point the OpenAI client at the local Ollama base URL and use instructor.Mode.JSON. You can then call chat.completions.create with a response_model against models like llama3.1.

Does Instructor support streaming partial results?▼

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 for real-time UI updates.

Why does my Pydantic validation keep failing on LLM output?▼

Overly strict patterns, such as rigid date regexes, cause repeated failures. Add clear field descriptions, use enums for fixed categories, and normalize flexible formats inside custom validators instead of rejecting them.