Overview
When you enable structured output, your agent will:- Process the input normally
- Extract information according to your schema
- Return validated, typed data matching your specification
- Ensure type safety and consistency
Structured output uses runtime schema generation and validation to ensure your agents return properly formatted data.
When to Use Structured Output
Data Extraction
Extract structured information from unstructured text (resumes, invoices, documents)
API Integration
Generate responses that match your API schema requirements
Database Inserts
Create records with validated fields for database operations
Multi-Agent Pipelines
Pass typed data between agents in complex workflows
Basic Configuration
Add thestructured_output field to your agent configuration:
Type Notation
Define field types using our type notation syntax:Basic Types
Text data
Integer numbers
Decimal numbers
Boolean values (true/false)
Collection Types
List of items of type T
Dictionary mapping keys of type K to values of type V
Enum types are not currently supported. Use
str type with clear descriptions for fields that should have restricted values. Validation must be handled in your system prompt or downstream processing.Quick Start Example
Extract contact information from text:Multi-Agent Data Passing
Use structured output to pass typed data between agents in workflows. Downstream agents can access structured outputs from previous agents using template variables in their system prompts.Accessing Structured Output in Prompts
Use the{{ agent_name.output_name.field }} syntax to inject structured output into agent prompts:
{{ agent_name.output.field }}- Access specific field from structured output{{ agent_name.output.nested.field }}- Access nested fields{{ agent_name.output }}- Access entire structured output as JSON{{ user_input }}- Latest user message{{ history[N] }}- Last N messages from conversation
Multi-Agent Example
Pass structured data between agents:Best Practices
Configuration Reference
Schema Structure
Thestructured_output field has the following structure:
Configuration for structured output generation
Field Specification
Each field in the schema must have:Type notation for the fieldSee Type Notation Reference for all supported types.Supported types:
str, int, float, bool, list[T], dict[K, V]Human-readable description of what this field representsThe agent uses this description to understand what data to extract. Be specific and clear.
Agent Type Support
llm_agent: ✅ Fully supported - LLM agents can generate structured output for any schema
react_agent: ✅ Fully supported - ReAct agents generate structured output after completing their tool-calling iterations
Validation and Error Handling
The system automatically validates structured output:Type Checking: Values must match the declared type
Required Fields: All fields in the schema must be present in the output
Format Validation: Basic format checking for strings, numbers, etc.
Common Errors
| Error | Cause | Solution |
|---|---|---|
Invalid type notation | Unsupported type syntax | Check Type Notation Reference |
Missing required field | Agent didn’t provide all fields | Improve system prompt to mention all fields |
Type validation failed | Value doesn’t match expected type | Ensure agent outputs correct type for the field |
Type mismatch | Wrong data type | Ensure agent outputs correct type (e.g., number not string) |
Example Error Response
If validation fails, you’ll receive a detailed error:Limitations
- Structured output is currently supported for
llm_agentandreact_agenttypes - Complex nested objects may require careful prompt engineering
- Very large schemas (>20 fields) may impact performance
- All fields are required (no optional fields)
- Output must be valid JSON
Next Steps
Conditional Edges
Learn how to route agents based on structured output values