Parameters
z.ZodType<OBJECT>
required
The Zod schema that defines the shape of the object.Supports both Zod v3 and Zod v4.
boolean
default:"false"
Enables support for references in the schema.
This is required for recursive schemas, e.g. with
z.lazy.However, not all language models and providers support such references.Returns
Returns aSchema<OBJECT> that can be used with AI SDK functions. The type is automatically inferred from the Zod schema.
Examples
Basic Zod schema
With tool
Complex nested schema
With refinements and transforms
Recursive schema
Array schema
Union types
With default values
Optional and nullable fields
Enum schema
Zod v3 vs Zod v4
ThezodSchema function automatically detects and handles both Zod v3 and Zod v4:
Type Inference
The main advantage ofzodSchema over jsonSchema is automatic type inference:
Notes
When using descriptions on schema properties (via
.describe()), the descriptions are passed to the language model
to help it understand what values to generate.Recursive schemas require
useReferences: true, but not all providers support JSON Schema references.
Test with your specific provider before using in production.