Signal · Validation and retries

JSON extraction from prose

When a response has prose or a code fence around the JSON, Signal extracts the JSON value and accepts it only if it passes schema validation. Example: a sentence and a json code fence around a valid booking, which takes one request and no retry. The model’s reply is scripted; no model is called.

Schema
z.object({ show: z.string(), seats: z.number() })
Scripted model reply
Here is the booking:
```json
{"show":"The Tempest","seats":2}
```
Anything else?
Output
{
  response: { show: 'The Tempest', seats: 2 },
  requests: 1,
  retries: 0,
}
Output matches the expected value

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