A Fail-Closed Checklist for AI Output Parsers
An invoice extractor can return perfectly valid JSON while omitting the total. Showing that missing total as zero changes the meaning of the invoice. This is a workflow error: a value the extractor could not establish ha
An invoice extractor can return perfectly valid JSON while omitting the total. Showing that missing total as zero changes the meaning of the invoice. This is a workflow error: a value the extractor could not establish has been allowed to reach a screen that presents it as known.
Define the acceptance boundary
For an example contract that uses integer minor units, require a currency, a total and a source-document reference. Define the permitted currency and sign rules for this particular document type. A zero total can be valid; a missing total is a different state. Validate the response before constructing the record that downstream code considers accepted.
| Input fixture | Expected outcome |
|---|---|
| An invoice matching the contract, with a legitimate zero total | Accepted if the source also supports that amount |
| Object omits the total | Needs review; no default zero |
| String in a field defined as an integer | Needs review; no silent conversion |
| Unreadable response or timeout | No accepted record; retain a bounded diagnostic |
| Well-shaped output with an amount absent from the source | Fails the separate source check |
The schema deals with presence and representation. It cannot verify what the scanned document actually says. For structured financial fields, also check what source evidence must exist and who may resolve discrepancies. If the input is ambiguous, returning to the source document is more useful than asking a model to guess a second time.
Follow the rejected case all the way to the UI
A rejection should lead to a visible review reason and a reference that an authorized reviewer can open. Check the UI, exports and downstream jobs for accidental defaulting. Record whether the corrected value was supplied by the reviewer or extracted automatically. Before enabling the extractor, exercise one case from each row and decide what happens when the review queue reaches the age or size your team can handle. These are proposed fixtures for your system.
In JSON Schema, declaring a property and requiring its presence are separate operations. JSON Schema object properties.
This article was created with AI assistance.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.