Skip to main content
Create a structured-output contract from Zod or JSON Schema.

Param

schema Shape that valid model output must satisfy.

Param

options Optional bounded retry count.

Throws

Invalid schema or retry count.

Example

Call Signature

Create a structured-output contract from Zod or JSON Schema.

Type Parameters

Schema

Schema extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

Parameters

schema

Schema Shape that valid model output must satisfy.

options?

Optional bounded retry count.
maxRetries?
number

Returns

OutputFormatSpec<output<Schema>> A serializable JSON Schema format with an inferred output type.

Throws

Invalid schema or retry count.

Example

Call Signature

Create a structured-output contract from Zod or JSON Schema.

Type Parameters

Output

Output = unknown

Parameters

schema

Record<string, unknown> Shape that valid model output must satisfy.

options?

Optional bounded retry count.
maxRetries?
number

Returns

OutputFormatSpec<Output> A serializable JSON Schema format with an inferred output type.

Throws

Invalid schema or retry count.

Example