Parameters
JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>)
required
The JSON Schema for the schema. Can be:
- A JSON Schema object (JSONSchema7)
- A promise that resolves to a JSON Schema object
- A function that returns a JSON Schema object or promise
(value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>
Optional validation function for the schema.If provided, this function will be called to validate values against the schema.
Should return
{ success: true, value: OBJECT } on success or { success: false, error: Error } on failure.Returns
Returns aSchema<OBJECT> that can be used with AI SDK functions.
Examples
Basic JSON Schema
With custom validation
Complex nested schema
With enum values
Lazy schema initialization
Array schema
With definitions and references
Type Inference
When usingjsonSchema, the TypeScript types must be provided manually:
zodSchema instead.