Overview
StructuredOutputError is raised when the agent fails to produce valid structured output after exhausting all retry attempts. It provides detailed information about what went wrong, including validation errors and the last LLM response.
Class Definition
Properties
str
A human-readable description of the failure, including the number of attempts made.
List[Dict[str, Any]]
List of Pydantic validation errors or custom error dictionaries explaining what was invalid.For Pydantic validation errors, each dict typically contains:
type: The error type (e.g.,"missing","type_error")loc: The location in the schema where the error occurredmsg: A human-readable error messageinput: The invalid input value
Any
The raw content from the last LLM response before the error was raised. Useful for debugging what the LLM actually returned.
Basic Usage
Error Types
JSON Decode Errors
When the LLM returns invalid JSON:Schema Validation Errors
When JSON is valid but doesn’t match the Pydantic schema:Unexpected Errors
For other errors during structured output processing:Handling Strategies
Graceful Fallback
Retry with Simpler Schema
Logging and Monitoring
Common Causes
Debugging Tips
- Check the last response: The
last_responsefield shows exactly what the LLM returned:
- Inspect validation errors: The errors show exactly what failed:
- Test your schema manually:
See Also
- RetryConfig - Configure retry behavior
- AgentResult - Successful result with structured_data
- Structured Output Guide - Complete usage guide