structuredOutput to force the agent to respect a zod schema. Always build the schema with Output.object({ schema: z.object(...) }) so OpenAI/Google models get the right hints and TypeScript infers your payload automatically.
Output.objectoffers an ergonomic builder for the expected payload.- Schema descriptions are forwarded to the model to boost accuracy.
- If parsing fails, the SDK throws—catch it to retry or log the error.
Targeted extraction
Tips
- Prefer
agent.generatefor structured generation—streaming + schemas remains experimental. - Log parsing errors to fine-tune prompts or trigger retries.
- Separate “strict” outputs (IDs, metadata) from free-form content (summaries, answers).
Scaleway models
Scaleway’s OpenAI-compatible endpoint still validates schemas client-side. The SDK now infersAgentStructuredOutput straight from your Zod schema, so you can keep the exact same builder and pass it to Scaleway without extra generics:
codeSchema is typed as AgentStructuredOutput<typeof schema>, keeping the Scaleway requirements and your DX identical to OpenAI/Google workflows.
When you target a non-OpenAI provider without tools, AI Kit now goes straight togenerateObject. Your original (text or multimodal) messages are enough to populateexperimental_output; there’s no need to remind the model to “answer in JSON”.