Skill metadata
Reference: full SKILL.md
The following is the complete skill definition that Mibyan loads when this skill is triggered. This is what the agent sees as instructions when the skill is active.
Instructor: Structured LLM Outputs
When to Use This Skill
Use Instructor when you need to:- Extract structured data from LLM responses reliably
- Validate outputs against Pydantic schemas automatically
- Retry failed extractions with automatic error handling
- Parse complex JSON with type safety and validation
- Stream partial results for real-time processing
- Support multiple LLM providers with consistent API
Installation
Quick Start
Basic Example: Extract User Data
With OpenAI
Core Concepts
1. Response Models (Pydantic)
Response models define the structure and validation rules for LLM outputs.Basic Model
- Type safety with Python type hints
- Automatic validation (word_count > 0)
- Self-documenting with Field descriptions
- IDE autocomplete support
Nested Models
Optional Fields
Enums for Constraints
2. Validation
Pydantic validates LLM outputs automatically. If validation fails, Instructor retries.Built-in Validators
Custom Validators
Model-Level Validation
3. Automatic Retrying
Instructor retries automatically when validation fails, providing error feedback to the LLM.- LLM generates output
- Pydantic validates
- If invalid: Error message sent back to LLM
- LLM tries again with error feedback
- Repeats up to max_retries
4. Streaming
Stream partial results for real-time processing.Streaming Partial Objects
Streaming Iterables
Provider Configuration
Anthropic Claude
OpenAI
Local Models (Ollama)
Common Patterns
Pattern 1: Data Extraction from Text
Pattern 2: Classification
Pattern 3: Multi-Entity Extraction
Pattern 4: Structured Analysis
Pattern 5: Batch Processing
Advanced Features
Union Types
Dynamic Models
Custom Modes
Context Management
Error Handling
Handling Validation Errors
Custom Error Messages
Best Practices
1. Clear Field Descriptions
2. Use Appropriate Validation
3. Provide Examples in Prompts
4. Use Enums for Fixed Categories
5. Handle Missing Data Gracefully
Comparison to Alternatives
When to choose Instructor:
- Need structured, validated outputs
- Want type safety and IDE support
- Require automatic retries
- Building data extraction systems
- DSPy: Need prompt optimization
- LangChain: Building complex chains
- Manual: Simple, one-off extractions
Resources
- Documentation: https://python.useinstructor.com
- GitHub: https://github.com/jxnl/instructor (15k+ stars)
- Cookbook: https://python.useinstructor.com/examples
- Discord: Community support available
See Also
references/validation.md- Advanced validation patternsreferences/providers.md- Provider-specific configurationreferences/examples.md- Real-world use cases

