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]"