Skip to main content
When providing your Team with a structured output format to follow, you will normally prefer to do so using a Pydantic model. You can read more about structured outputs here. If you need to use provider-specific schema formats, you can also use a simple JSON dict as schema, instead of a Pydantic model. For example:
1

Add the following code to your Python file

json_schema_output.py
from agno.agent import Agent
from agno.team import Team
from agno.models.openai import OpenAIChat
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.utils.pprint import pprint_run_response

stock_schema = {
    "type": "json_schema",
    "json_schema": {
        "name": "StockAnalysis",
        "schema": {
            "type": "object",
            "properties": {
                "symbol": {"type": "string", "description": "Stock ticker symbol"},
                "company_name": {"type": "string", "description": "Company name"},
                "analysis": {"type": "string", "description": "Brief analysis"},
            },
            "required": ["symbol", "company_name", "analysis"],
            "additionalProperties": False,
        },
    },
}

stock_searcher = Agent(
    name="Stock Searcher",
    model=OpenAIChat("gpt-4o"),
    role="Searches for information on stocks and provides price analysis.",
    tools=[DuckDuckGoTools()],
)

company_info_agent = Agent(
    name="Company Info Searcher",
    model=OpenAIChat("gpt-4o"),
    role="Searches for information about companies and recent news.",
    tools=[DuckDuckGoTools()],
)

team = Team(
    name="Stock Research Team",
    model=OpenAIChat("gpt-4o"),
    respond_directly=True,
    members=[stock_searcher, company_info_agent],
    markdown=True,
)

response = team.run(
    "What is the current stock price of NVDA?",
    output_schema=stock_schema,
)

pprint_run_response(response)
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 ddgs
4

Export your OpenAI API key

  export OPENAI_API_KEY="your_openai_api_key_here"
5

Run the example

python json_schema_output.py