Structured output ensures agents return responses in a defined, validated format. Rather than receiving free-form text that you need to parse and validate yourself, you get type-safe data objects (Pydantic models, dataclasses, or TypedDict) that are immediately usable in your application.
This eliminates the need for manual parsing, reduces errors, and provides type safety throughout your codebase.
Common use cases include extracting structured data from documents, parsing user input, generating API responses, and building data pipelines.
Structured output works with most models. DeepSeek and Qwen do not support structured output. Only Anthropic, OpenAI, xAI, and Cohere support tools + structured output together.
Schema Types
Define your response schema using Pydantic models, dataclasses, or TypedDict. Each has different strengths:
Non-Streaming
Get structured responses using run() or arun() with the output_type parameter:
Streaming
Stream structured responses using stream() or astream():
Response Format:
When using structured output, response.content is an instance of your schema: