defineJsonResponse
Purpose and behavior
Section titled “Purpose and behavior”Declare a response read from the last complete <tag>…</tag> pair, parsed as JSON, optionally inside a Markdown code fence, then checked by schema. A missing tag, invalid JSON, schema issues or a thrown parse error fail with ResponseError; an invalid tag or repairs fails with code configuration.
Complete example and detailed rules.
Parameters and properties
Section titled “Parameters and properties”optionsRequiredJsonResponseOptions<T>Tag name, schema or parsing function, and the number of repair turns allowed after an invalid answer.options.tagRequiredstringTag name without angle brackets: a letter followed by letters, digits, _ or -. Another form fails with code configuration.options.schemaRequiredStandardValidator<T> | ((input: unknown) => T | Promise<T>)Standard Schema validator, such as Zod or Valibot, or a function that receives the parsed JSON as unknown and returns the typed value. Reported issues or a thrown error reject the answer.options.repairsOptionalnumber | undefinedCorrection turns allowed after an invalid answer, default 0; must be a nonnegative integer. Above 0, the agent must be able to resume its conversation.