instructor

Extract structured data from LLM responses with Pydantic validation.

1|Updated May 21, 2026
One-click install
npx skills add https://github.com/blueskies1818/hermesALIone --skill instructor-blueskies1818
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: instructor
Source: https://github.com/blueskies1818/hermesALIone/tree/main/Agent/optional-skills/mlops/instructor
Command: npx skills add https://github.com/blueskies1818/hermesALIone --skill instructor-blueskies1818

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill extracts structured data from LLM responses using Pydantic validation, automates retries for failed extractions, provides type safety and streaming capabilities, and integrates with multiple LLM providers.

Core Features & Use Cases

  • Structured Data Extraction: Extract data from LLM responses with Pydantic validation and predefined response models.
  • Automatic Validation and Retries: Validate and automatically retry failed data extractions for accuracy.
  • Type Safety and Streaming: Ensure data accuracy with type-safe Pydantic models and stream partial results for real-time processing.
  • Provider Support: Integrate with multiple LLM providers such as OpenAI, Anthropic, and local models with Ollama.
  • Use Case: Automate the extraction of user information from LLM responses with confidence, even when the data is missing or incomplete.

Quick Start

Use the instructor skill to extract structured user data from an LLM response.

import instructor
from pydantic import BaseModel
from anthropic import Anthropic

# Define output structure
class User(BaseModel):
    name: str
    age: int
    email: str

# Create instructor client
client = instructor.from_anthropic(Anthropic())

# Extract structured data
user = client.messages.create(
    model="claude-sonnet-4-5-20250929",
    max_tokens=1024,
    messages=[{
        "role": "user",
        "content": "John Doe is 30 years old. His email is [email protected]"
    }],
    response_model=User
)

print(user.name)   # "John Doe"
print(user.age)    # 30
print(user.email)  # "[email protected]"

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 using Pydantic?

Extract structured data from LLM responses by defining a Pydantic BaseModel and passing it as the response model to an instructor client, which validates the output and ensures type safety for fields like name, age, and email.

Does instructor work with Anthropic and OpenAI for structured output?

Yes, instructor supports structured output across multiple LLM providers including OpenAI, Anthropic, and local models via Ollama, allowing you to switch providers while maintaining consistent Pydantic validation.

What's the best way to handle incomplete data extraction from LLMs?

Handle incomplete data extraction by enabling automatic validation and retries, which prompts the LLM again to correct missing or invalid fields until the response matches your predefined Pydantic model.

Can I stream partial results when extracting structured data from an LLM?

Yes, you can stream partial results during structured data extraction, enabling real-time processing of LLM responses as they are generated and validated against your Pydantic models.

Why does my LLM data extraction fail type validation?

LLM data extraction fails type validation when the response does not match the predefined Pydantic model structure, which is resolved by instructor's automatic retry mechanism that re-prompts the LLM for correct data.