Structured Outputs guarantees the shape of the reply, not the sense of the values inside it. A model can return a valid age of minus 5 or a total that does not match the line items, and the schema will pass it. Value validation is a separate step in your code, and it is the step that catches the errors the schema cannot see.
Before you start
A set of structured outputs from your pipeline, and the rules each value must follow, such as ranges, formats and totals.
List the value rules per field
For each field, write the rule the value must pass: a range for numbers, a format for dates, a member of the enum for coded values, and a total that equals the sum of its parts for amounts.
Include the cross-field rules: a due date after the invoice date, a total equal to subtotal plus tax, a count that matches the number of items listed.
Check every field, not a sample
Run the rules over every reply, not a random sample, because value errors are rare and a sample can miss them. Record which rule failed and which field it was, so patterns show up.
Check totals by recomputing them from the parts: add the line items yourself and compare with the stated total.
Reject or repair, never silently accept
Decide per rule whether a failure means rejecting the reply and retrying, or repairing it in code. A wrong total should be recomputed, not accepted; an out-of-range age should be rejected, not clamped silently.
Log every failure with the raw reply, so you can tell whether the model, the schema or the source document is at fault.
Practice check: fictional Maple Corner extraction, 20 replies, 6 fields each
The table below is fictional practice material, worked out by hand from the stated validation runs. It is the expected result for the practice replies, not a run of any API.
| Rule | Checked | Failed | Action |
|---|---|---|---|
| Total equals sum of lines | 20 | 2 | Recompute total |
| Date format YYYY-MM-DD | 20 | 0 | None |
| Amount above zero | 20 | 1 | Reject reply |
| Currency in enum | 20 | 0 | None |
Three failures in 120 field checks: two totals that do not add up and one negative amount. All three are caught by value rules the schema cannot express.
Expected result. UNTESTED: the counts in the practice table are worked out by hand, not measured by running a validation step. Write the value rules for your own fields, run them over every reply, and log which rule failed.
Limits
- Value validation needs the rules written down first: a rule you have not written cannot be checked.
- Retrying a failed reply can return the same wrong value; a repeated failure means the source or the schema needs fixing, not another retry.
