instructor

Extract structured data from LLM responses with Pydantic validation.

4|Updated Apr 19, 2026
One-click install
npx skills add https://github.com/ragnarokhaa/hermes --skill instructor-ragnarokhaa
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: instructor
Source: https://github.com/ragnarokhaa/hermes/tree/main/hermes-cerul-tech-news-package/hermes-cerul-tech-news-package/hermes-agent/optional-skills/mlops/instructor
Command: npx skills add https://github.com/ragnarokhaa/hermes --skill instructor-ragnarokhaa

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill solves the problem of extracting structured data from LLM responses with Pydantic validation, ensuring reliable and efficient data extraction processes.

Core Features & Use Cases

  • Structured Data Extraction: Extracts structured data from LLM responses with Pydantic validation.
  • Automatic Validation: Validates outputs against Pydantic schemas automatically.
  • Retry Mechanism: Retries failed extractions automatically with error handling.
  • JSON Parsing: Parses complex JSON with type safety and validation.
  • Streaming Results: Streams partial results for real-time processing.
  • Multi-provider Support: Supports multiple LLM providers with a consistent API.
  • Use Case: For instance, extracting user information from text, classifying content, or extracting entities from text.

Quick Start

To extract user data, install Instructor and run the following Python code:

import instructor
from pydantic import BaseModel
from anthropic import Anthropic

class User(BaseModel):
    name: str
    age: int
    email: str

client = instructor.from_anthropic(Anthropic())
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 with Pydantic validation?

Structured data extraction from LLM responses with Pydantic validation is achieved by defining a BaseModel schema and passing it as the response model to automatically validate and parse the LLM output into typed Python objects.

Can I use Anthropic and OpenAI models for structured data extraction?

Yes, structured data extraction supports multiple LLM providers including Anthropic and OpenAI, offering a consistent API to extract and validate Pydantic models across different language models.

How do I handle failed JSON parsing or invalid LLM outputs?

Failed JSON parsing and invalid LLM outputs are handled through an automatic retry mechanism that re-prompts the LLM with error context, ensuring the extraction process reliably produces valid structured data.

What is the best way to stream partial LLM results for real-time processing?

Streaming partial LLM results for real-time processing is supported natively, allowing you to receive and interact with incremental structured data chunks as the language model generates the response.

Do I need Pydantic to extract structured data from text?

Yes, Pydantic is a required dependency for structured data extraction, providing the type safety and schema validation needed to parse complex JSON and ensure the LLM output matches your defined data models.