Skip to main content
Set outputSchema on an Agent to make it return JSON that matches your schema.
Structured output is OpenAI-only in v1.7.4. Non-OpenAI providers log a warning and continue without structured output (see Provider support).

Quick Start

1

Simplest — one outputSchema

2

With outputSchemaName and a nested schema


How It Works

The agent forwards outputSchema to OpenAI as response_format: { type: 'json_schema', json_schema: { name, schema } } and returns the raw JSON string.
outputSchema is a JSON Schema object (Record<string, any>), not a Zod schema. If you keep schemas in Zod, convert first with zodToJsonSchema(MySchema).

Provider support

Structured output works with OpenAI models today. On a non-OpenAI provider the agent skips structured output and logs this warning verbatim:
Grep your logs for outputSchema is not yet supported to confirm whether a provider dropped it.

Multi-turn behaviour

Structured output goes through the agent’s full message history, so follow-up prompts see prior turns and stay consistent.

How this differs from generateObject

The low-level provider.generateObject({ schema }) from resolveBackend is still available for direct AI SDK use. The recommended, agent-centric path is outputSchema on the Agent.
See the Zod docs for schema construction.

Common Patterns

Extraction

Classification

Sentiment


Best Practices

List every field you always expect in required. It nudges the model to include them and keeps the JSON predictable.
Add enum on classification fields so the model can only pick valid values.
The agent returns a JSON string. Call JSON.parse(result) to get an object.
Structured output is OpenAI-only in v1.7.4. On other providers the agent logs a warning and returns unstructured text.

Agent

Agent configuration

Multi-Provider (AI SDK)

Switch LLM providers