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