Input & Output

Pass strings or Pydantic models to agents and teams, then control the response shape.

Agents and teams accept strings, dictionaries, messages, and Pydantic models. Start with strings. Add schemas when you need validation.

Setup

Install the dependencies in your Python environment and set your OpenAI API key:

pip install agno openai
export OPENAI_API_KEY="your-api-key"

Choose a Format

Use CaseFormat
Prototyping, chat interfacesString input and output
Data extraction, classificationStructured output
API responses, pipelinesStructured input and output

String I/O

String in, string out:

from agno.agent import Agent
from agno.models.openai import OpenAIResponses

agent = Agent(model=OpenAIResponses(id="gpt-5.2"))

response = agent.run("What's the capital of France?")
print(response.content)  # "The capital of France is Paris."

Structured I/O

Use Pydantic models to validate what goes in and what comes back:

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

class ReviewInput(BaseModel):
    text: str
    product_id: str

class SentimentResult(BaseModel):
    sentiment: str = Field(description="positive, negative, or neutral")
    confidence: float = Field(ge=0, le=1)
    summary: str = Field(description="One sentence summary")

agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    output_schema=SentimentResult,
)

response = agent.run(
    input=ReviewInput(text="Love this product!", product_id="SKU-123")
)

if not isinstance(response.content, SentimentResult):
    raise ValueError(f"Expected SentimentResult, got: {response.content!r}")
result = response.content
print(result.sentiment)   # "positive"
print(result.confidence)  # 0.95

Guides

Advanced I/O Features