Skip to main content
Use 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.object offers 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.generate for 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 infers AgentStructuredOutput straight from your Zod schema, so you can keep the exact same builder and pass it to Scaleway without extra generics:
Behind the scenes 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 to generateObject. Your original (text or multimodal) messages are enough to populate experimental_output; there’s no need to remind the model to “answer in JSON”.