Basic Usage
Define a Pydantic model and pass it asoutput_schema:
How It Works
When you setoutput_schema, Agno:
- Converts your Pydantic model to a JSON schema
- Passes this schema to the model’s structured output API (if supported)
- Validates the response against your schema
- Returns a typed Pydantic object in
response.content
Control output_schema Per-Run
Override or set the schema at run time:
With Tools
Structured output works alongside tools. The agent calls tools during execution, then formats the final response according to your schema:Schema Design Tips
Use Field Descriptions
Descriptions guide the model on what to generate:Use Constraints
Pydantic validators ensure valid output:Use Optional for Uncertain Fields
Mark fields as optional when data might not be available:Common Patterns
Data Extraction
Classification
Multi-Item Generation
Fallback with use_json_mode
Enable JSON mode for models that don’t support structured output natively:
JSON mode instructs the model to respond in JSON but doesn't guarantee schema compliance. Prefer models with native structured output support.
Related
- Team Structured Output: Configure structured output for teams
- Output Model: Use a separate model to structure output
- Structured Input: Pass validated input to agents