Skip to main content
Use input_schema to automatically validate dictionary inputs against a Pydantic model. This ensures type safety and data validation before the agent processes the request.

Code

input_schema_on_agent.py
from typing import List

from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.tools.hackernews import HackerNewsTools
from pydantic import BaseModel, Field


class ResearchTopic(BaseModel):
    topic: str
    focus_areas: List[str] = Field(description="Specific areas to focus on")
    target_audience: str = Field(description="Who this research is for")
    sources_required: int = Field(description="Number of sources needed", default=5)


agent = Agent(
    name="Research Agent",
    model=OpenAIResponses(id="gpt-5.2"),
    tools=[HackerNewsTools()],
    role="Research topics from HackerNews",
    input_schema=ResearchTopic,
)

# Pass a dict - automatically validated against ResearchTopic
agent.print_response(
    input={
        "topic": "AI Agents",
        "focus_areas": ["Multi-agent systems", "Tool use"],
        "target_audience": "Developers",
        "sources_required": 5,
    },
    stream=True,
)

Usage

1

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate
2

Install dependencies

uv pip install -U agno openai
3

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"
4

Run Agent

python input_schema_on_agent.py