Validate JSON against a schema
validate_jsonChecks model-produced JSON against a JSON Schema and returns where it fails with the offending value quoted, so you can retry before acting. Accepts bare values or JSON in prose.
Instructions
Validate candidate output text against a JSON Schema and say what is wrong. Answers {valid, feedback}: when invalid, hand feedback back to the model and retry — it says where the document fails and quotes the offending value, clipped to 200 characters; when valid, feedback is null. Use it on any JSON a model produced before acting on it; for a shift-work checkpoint call shiftwork_status or shiftwork_clock_in instead, which validate against the shipped checkpoint schema themselves. output may be a bare JSON value; otherwise the first fenced code block, else the first object or array in the text, is what gets validated. $schema selects draft-04, draft-06, draft-07, 2019-09 or 2020-12 (the default). $ref resolves only inside the one schema given (#, #/..., #name): a remote reference or an embedded $id is refused with its own sentence, never fetched. pattern is Python re syntax without inline flags, look-behind, backreferences, atomic, possessive or conditional groups or \N{...}, and all of a document's patterns share 500 ms: past that the answer is one refusal sentence naming the pattern that ran out, not a partial validation. Reads nothing but its two arguments and writes nothing.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| output | Yes | The text to validate, as the model returned it: a JSON value, or prose holding a fenced code block or a JSON object/array. | |
| schema | Yes | The JSON Schema object (draft-04 through 2020-12) the output must satisfy; `$ref` may only point inside it. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| valid | Yes | True when the extracted JSON satisfies the schema. | |
| feedback | Yes | null when valid; otherwise where the document fails and the clipped offending value, to hand back to the model. |