Signal · Validation and retries

Retry on validation failure (onRetry)

When a response fails schema validation, Signal calls the .onRetry() handler with the error and the attempt number, appends the response and the validation error to the conversation, and sends the request again. Example: seats arrives as a string, and the second response passes. The model’s replies are scripted, the correction message is Signal’s, and no model is called.

Schema
z.object({ show: z.string(), seats: z.number() })
Prompt
'Two for The Tempest on Saturday, please. Grace'
Run, turn by turn
Scripted model reply
{"show":"The Tempest","seats":"two"}
onRetry arguments
{
  attempt: 1,
  message: 'Response failed schema validation: seats: Invalid input: expected number, received string',
}
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.