outputSchema on an Agent to make it return JSON that matches your schema.
outputSchema works on every provider (OpenAI, Anthropic, Google, Groq, Mistral, Ollama, and more). On OpenAI it uses response_format: json_schema natively; on other providers it routes through the AI SDK backend’s generateObject({ schema }). Cross-provider support landed in PraisonAI PR #4412 — earlier releases dropped the schema on non-OpenAI providers.Quick Start
1
Simplest — one outputSchema
2
With outputSchemaName and a nested schema
How It Works
On OpenAI, the agent forwardsoutputSchema as response_format: { type: 'json_schema', json_schema: { name, schema } }. On other providers it routes the schema through the AI SDK backend’s generateObject({ schema }). Both paths return 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
outputSchema works on every provider PraisonAI TS supports today.
The agent returns a JSON string that matches your schema in both paths —
JSON.parse(result) for the object.
Cross-provider structured output landed in PraisonAI PR #4412. If you are on an earlier release, the agent logs outputSchema is not yet supported with non-OpenAI providers ... — proceeding without structured output and returns unstructured text.
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.Works on every provider
Works on every provider
Switching the
llm string from openai/... to anthropic/..., google/..., or any other supported provider does not change your outputSchema code. Structured output is guaranteed on every provider from PraisonAI PR #4412 onward.Related
Agent
Agent configuration
Multi-Provider (AI SDK)
Switch LLM providers

