Topic 5 of 5 · 4 min read
Catching invented values in vision output
Goal: Add validation rules and a review queue that catch a misread total or invented field before extracted data reaches the business system.
Never let extracted values reach your business system on the model's word alone: check them with rules, measure them on labeled samples, and send doubtful ones to a person. A model gives no honest signal of when it is wrong, so the checks must come from outside it.
Check yourself · 1 of 3
Extracted line items sum to 1,480.00 but the extracted total is 4,180.00 with no tax. What should the pipeline do?
Why it matters
Vision output is wrong in a quiet way. A misread digit or an invented VAT number is formatted perfectly and passes a schema check. If the data posts to payments or stock, the error becomes a real cost. The goal is not zero errors. It is knowing which fields are wrong before anyone relies on them.
How to do it
- Build a labeled sample. Take 50 to 200 real documents, have a person write the correct values, and keep them as a test set. Include your worst scans and handwriting.
- Measure per field. Compare model output to the labels field by field, not document by document. A document-level score hides that
totalis 99% right andtax_idis 70% right. Re-run after every prompt, model or preprocessing change. - Add arithmetic rules. Line items must add up to the subtotal. Subtotal plus tax must equal the total. Quantity times unit price must equal the line amount. A failed rule means at least one value is wrong.
- Add format and range rules. Dates must exist, currency codes must be valid, a tax rate must be a rate your country uses, a total must not be negative.
- Check against the source. If you also run OCR, every extracted number should appear in the OCR text. A value that does not is a candidate for invention.
- Flag, do not guess. Mark a field for review when a rule fails, when two reads disagree, when it is null but required, or when the model's own confidence note is low. Treat model confidence as a hint only.
- Route to a person. The reviewer sees the page, the extracted value and the failed rule side by side, fixes it, and the fix is saved as a new labeled example.
Before and after
Before: JSON that matches the schema posts straight to accounting. A total of 4,180.00 was read instead of 1,480.00.
After: the rule "sum of lines equals subtotal" fails, the document goes to the review queue with the failing rule shown, and nothing is posted until a person confirms.
What goes wrong
Rules that are too loose let errors through, rules that are too strict flood the queue, and a model that adjusts one number to make the sum work hides the original mistake. Keep the raw first-pass values next to the final ones.
Examples
The total that does not add up
An invoice extraction returns lines of 420.00, 610.00 and 450.00, subtotal 1,480.00 and total 4,180.00. The rule "subtotal plus tax equals total" fails because 4,180.00 is not 1,480.00 plus 8% tax. The invoice goes to review, where the page shows 1,598.40.
A per-field scorecard
On 100 labeled receipts the scores are: date 99, total 97, merchant 95, tax id 71. The team does not ship auto-posting. It auto-posts date and total when the rules pass, and sends every tax id to review until the number improves.
Key points
- A schema-valid value can still be wrong, so validity is not correctness.
- Measure accuracy per field on a labeled sample that includes your hardest documents.
- Arithmetic cross-checks, such as lines adding up to the total, catch many misreads without a person.
- Treat model-reported confidence as a weak hint, and flag on failed rules and disagreements instead.
- Route flagged fields to a review queue showing the page and the failed rule, and save fixes as new labeled examples.
Common mistakes
- Scoring whole documents as right or wrong, which hides weak fields.
- Trusting the model's own confidence statement as if it were measured.
- Letting the model "fix" a number so the arithmetic works, which hides the original misread.
- Testing only on clean scans and being surprised by production quality.
Check yourself · 2 of 3
Why score a labeled sample per field rather than per document?
Check yourself · 3 of 3
Which signal is the weakest basis for deciding that an extracted field is correct?
Practice items, not counted towards your mastery.
Start here
- Vision (Claude docs) (opens in a new tab)DocsFree
Image size limits, token cost per image, and tips for prompt placement and resizing.
- Document understanding (Gemini API) (opens in a new tab)DocsFree
How a model reads PDFs as pages and layout, with extraction examples and file limits.
- Images and vision (OpenAI docs) (opens in a new tab)DocsFree
Image input formats, detail levels and the stated limits of vision models.