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 v3.0 translates
output_schema to Anthropic’s output_config.format request shape, which requires anthropic>=0.77.0 (the agno[anthropic] extra pins it). 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: