Skip to main content
This example demonstrates how to pass an output_schema to a specific agent run, allowing you to get structured output without setting a default schema on the agent.
1

Add the following code to your Python file

output_schema_on_run.py
from pydantic import BaseModel
from agno.agent import Agent
from agno.models.openai import OpenAIChat


class MovieReview(BaseModel):
    title: str
    rating: int
    summary: str


agent = Agent(model=OpenAIChat(id="gpt-4o-mini"))

response = agent.run(
    "Review the movie 'Inception'",
    output_schema=MovieReview,
    stream=False,
)

print(response.content)
2

Create a virtual environment

Open the Terminal and create a python virtual environment.
python3 -m venv .venv
source .venv/bin/activate
3

Install libraries

pip install -U agno openai
4

Export your OpenAI API key

  export OPENAI_API_KEY="your_openai_api_key_here"
5

Run the example

python output_schema_on_run.py