output_schema to return a validated Pydantic object instead of free-form text.
Code
structured_output.py
run.content is a MovieScript instance after Claude returns valid JSON and Agno validates it against the schema.
Agno 2.7.2 translates
output_schema to Anthropic’s legacy-compatible output_format request and adds the structured-outputs-2025-11-13 beta automatically. Anthropic’s current direct API uses output_config.format; the legacy request remains available during Anthropic’s migration period. Let Agno populate the request field when you use output_schema.max_tokens can end without a schema-valid result. Anthropic JSON outputs are also incompatible with citations and message prefilling; Agno disables document citations for these requests.
Usage
1
Set up your virtual environment
2
Install dependencies
3
Export your Anthropic API key
4
Run the agent
Save the code above as
structured_output.py, then run: