Skip to main content
Creates a schema using a JSON Schema definition. This is useful when you want to use JSON Schema directly instead of a validation library like Zod.

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 a Schema<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 using jsonSchema, the TypeScript types must be provided manually:
For automatic type inference, consider using zodSchema instead.