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 forwardsoutputSchema 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: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.Common Patterns
Extraction
Classification
Sentiment
Best Practices
Mark required fields
Mark required fields
List every field you always expect in
required. It nudges the model to include them and keeps the JSON predictable.Use enums for fixed choices
Use enums for fixed choices
Add
enum on classification fields so the model can only pick valid values.Parse the result
Parse the result
The agent returns a JSON string. Call
JSON.parse(result) to get an object.Keep to OpenAI for now
Keep to OpenAI for now
Structured output is OpenAI-only in v1.7.4. On other providers the agent logs a warning and returns unstructured text.
Related
Agent
Agent configuration
Multi-Provider (AI SDK)
Switch LLM providers

