Input & Output
Learn how to pass data to agents and handle their responses.
Agents accept input and generate output in many formats, from simple strings to validated Pydantic models. Start with strings, add structure when you need validation.
Format Types Usage
| Use Case | Format |
|---|---|
| Prototyping, chat interfaces | Strings work fine |
| Data extraction, classification | Structured output |
| API responses, pipelines | Structured input and output |
String I/O
String in, string out:
1from kern.agent import Agent2from kern.models.openai import OpenAIResponses34agent = Agent(model=OpenAIResponses(id="gpt-5.2"))56response = agent.run("What's the capital of France?")7print(response.content) # "The capital of France is Paris."Structured I/O
Use Pydantic models to validate what goes in and what comes back:
1from pydantic import BaseModel, Field2from kern.agent import Agent3from kern.models.openai import OpenAIResponses45class ReviewInput(BaseModel):6 text: str7 product_id: str89class SentimentResult(BaseModel):10 sentiment: str = Field(description="positive, negative, or neutral")11 confidence: float = Field(ge=0, le=1)12 summary: str = Field(description="One sentence summary")1314agent = Agent(15 model=OpenAIResponses(id="gpt-5.2"),16 output_schema=SentimentResult,17)1819response = agent.run(20 input=ReviewInput(text="Love this product!", product_id="SKU-123")21)2223result: SentimentResult = response.content24print(result.sentiment) # "positive"25print(result.confidence) # 0.95Guides
arrow-right-to-bracket
Structured Input
Validate data passed to agents and teams.
arrow-right-from-bracket
Structured Output
Get validated Pydantic objects instead of text.