Skip to main content
Agno Agents supports various forms of input and output, from simple string-based interactions to structured data validation using Pydantic models. The most standard pattern is to use str input and str output:
For more advanced patterns, see:

Structured Output

One of our favorite features is using Agents to generate structured data (i.e. a pydantic model). This is generally called “Structured Output”. Use this feature to extract features, classify data, produce fake data etc. The best part is that they work with function calls, knowledge bases and all other features. Structured output makes agents reliable for production systems that need consistent, predictable response formats instead of unstructured text. Let’s create a Movie Agent to write a MovieScript for us.
1

Structured Output example

movie_agent.py
2

Run the example

Install libraries
Export your key
Run the example
The output is an object of the MovieScript class, here’s how it looks:
Some LLMs are not able to generate structured output. Agno has an option to tell the model to respond as JSON. Although this is typically not as accurate as structured output, it can be useful in some cases.If you want to use JSON mode, you can set use_json_mode=True on the Agent.

Streaming Structured Output

Streaming can be used in combination with output_schema. This returns the structured output as a single RunContent event in the stream of events.
1

Streaming Structured Output example

streaming_agent.py
2

Run the example

Install libraries
Export your key
Run the example

Structured Input

An agent can be provided with structured input (i.e a pydantic model or a TypedDict) by passing it in the Agent.run() or Agent.print_response() as the input parameter.
1

Structured Input example

2

Run the example

Install libraries
Export your key
Run the example

Validating the input

You can set input_schema on the Agent to validate the input. If you then pass the input as a dictionary, it will be automatically validated against the schema.
1

Validating the input example

validating_input_agent.py
2

Run the example

Install libraries
Export your key
Run the example

Typesafe Agents

When you combine both input_schema and output_schema, you create a typesafe agent with end-to-end type safety - a fully validated data pipeline from input to output.

Complete Typesafe Research Agent

Here’s a comprehensive example showing a fully typesafe agent for research tasks:
1

Create the typesafe research agent

typesafe_research_agent.py
2

Run the agent

Install libraries
Set your API key
Run the agent
The output is a structured ResearchOutput object:

Using a Parser Model

You can use a different model to parse and structure the output from your primary model. This approach is particularly effective when the primary model is optimized for reasoning tasks, as such models may not consistently produce detailed structured responses.
Using a parser model can improve output reliability and reduce costs since you can use a smaller, faster model for formatting while keeping a powerful model for the actual response.
You can also provide a custom parser_model_prompt to your Parser Model to customize the model’s instructions.

Using an Output Model

You can use a different model to produce the run output of the agent. This is useful when the primary model is optimized for image analysis, for example, but you want a different model to produce a structured output response.
You can also provide a custom output_model_prompt to your Output Model to customize the model’s instructions.
Gemini models often reject requests to use tools and produce structured output at the same time. Using an Output Model is an effective workaround for this.

Developer Resources