Skip to main content
Structured outputs let you define the exact shape of agent responses using Pydantic models. The agent returns validated, type-safe data instead of free-form text.

Quick Start


Defining Output Models

Basic Model

With Descriptions

Use Field(description=...) to guide the model:

With Default Values

Nested Models

With Enums

With Lists

Optional Fields


Using Structured Outputs

With agent.run()

With Knowledge Bases

With Sessions (Memory)


Examples

Data Extraction

Sentiment Analysis

Content Classification

Entity Extraction

Task Breakdown


Best Practices

Use Descriptive Field Names

Add Clear Descriptions

Use Appropriate Types

Constrain Values Where Possible

Handle Optional Data


Error Handling


Supported Providers

Structured outputs work best with:
Some models handle structured outputs better than others. GPT-4o provides the most reliable structured output support.