Structured Outputs with stream=True
Use the Agent streaming interface with a Claude output schema and receive one validated result.
Pass stream=True to receive the validated result through the Agent streaming interface.
Code
from agno.agent import Agent
from agno.models.anthropic import Claude
from pydantic import BaseModel
class TravelPlan(BaseModel):
destination: str
days: int
activities: list[str]
structured_output_agent = Agent(
model=Claude(id="claude-sonnet-4-6"),
description="You create concise travel plans.",
output_schema=TravelPlan,
)
if __name__ == "__main__":
structured_output_agent.print_response(
"Plan a three-day trip to Kyoto.",
stream=True,
)Agno sets stream_model_response=False when an Agent has output_schema, parse_response=True, and no parser model. Claude completes one non-streaming request. Agno validates it and then emits one TravelPlan result through the Agent streaming interface. Use a standard run() for direct access to the validated object.
This buffered path has the same model, schema, refusal, max_tokens, citation, and message-prefill constraints as non-streaming structured output.
Usage
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U "agno[anthropic]"Export your Anthropic API key
export ANTHROPIC_API_KEY="your_anthropic_api_key_here"Run the agent
Save the code above as structured_output_stream.py, then run:
python structured_output_stream.py