Skip to content
mentoor

Topic 4 of 4 · 4 min read

Checking extracted data against the source document

Goal: Compare a model's extraction from an invoice or form against the source and find invented or misread values.

Treat every extracted value as a claim that needs a check, and build the check into the pipeline. A model reads documents well most of the time. When it fails, it fails fluently: a clean JSON object with one wrong digit.

Check yourself · 1 of 3

An extraction returns clean JSON from a blurry scan. What does this tell you about its correctness?

Choose one answer

Why it matters

An invoice total off by one digit pays the wrong amount. Claude's vision guide says plainly that the model might hallucinate or make mistakes on low-quality, rotated or very small images, and that outputs should be verified for high-stakes use. Other providers say similar things. Your pipeline has to catch what the model cannot.

Typical failures

  • Misread digits. 8 and 6, 1 and 7, a comma read as a dot. Common on faint scans and fax-quality pages.
  • Invented cells. A table row is truncated, so the model completes it with a plausible value.
  • Merged or shifted columns. Values land under the wrong header when a table has no ruling lines.
  • Rotated and handwritten pages. Rotated pages and handwriting are read far less reliably than clean print.
  • Silent omissions. A field missing from the page comes back as a guess rather than null.

How to verify

  1. Allow null. The schema should let each field be null, and the prompt should say to return null when the value is not visible.
  2. Ask for evidence. Request the page and the exact text the value came from, then check that the text appears in the source.
  3. Run arithmetic checks. Line items must sum to the subtotal; subtotal plus tax must equal the total; dates must parse and be in order.
  4. Validate formats. An IBAN, a VAT number or a currency code has a checksum or pattern. Reject what fails.
  5. Normalize pages first. Rotate pages upright and prefer clean scans before extraction.
  6. Sample and escalate. Have a person compare a random sample against the source each week, and route low-confidence or failed-check documents to review.

Before and after

{ "invoice_no": "INV-2291", "subtotal": 1180.00, "tax": 236.00, "total": 1316.00 }

This looks fine. But 1180.00 plus 236.00 is 1416.00, not 1316.00. One of the numbers is misread, and a sum check catches it. Better output carries evidence and nulls:

{ "total": { "value": 1416.00, "page": 1, "quote": "TOTAL DUE 1,416.00" } }

What goes wrong

  • Checking the model with the model. Asking it "is this right?" often confirms the first answer.
  • Sampling too little. An error rate of 1 in 200 needs far more than ten documents to see.

Examples

Sum check catches a misread

The extraction reports line items 420.00, 310.00 and 450.00 with a subtotal of 1,180.00. The items add up to 1,180.00, so the subtotal agrees. The total is 1,316.00 with tax 236.00, but 1,180.00 plus 236.00 is 1,416.00. The total or the tax is wrong. Flag the document and compare against the source image.

Evidence field

{"iban": {"value": "DE89 3704 0044 0532 0130 00", "page": 2, "quote": "IBAN DE89 3704 0044 0532 0130 00"}}

Code can check that the quote appears in the page text and that the IBAN passes its checksum before the value is accepted.

Key points

  • Fluent, well-formed JSON can still hold a misread digit or an invented cell, so every value needs a check.
  • Faint scans, rotated pages, handwriting and small images are the documented weak spots for vision input.
  • Let fields be null and tell the model to return null for anything not visible, to avoid guessed values.
  • Ask for the page and quoted source text for each value, then confirm the quote exists in the document.
  • Use arithmetic and format checks in code, and send failures and a random sample to human review.

Common mistakes

  • Accepting well-formed JSON as correct without a sum, format or evidence check.
  • Forcing every field to be required, so the model guesses values that are missing from the page.
  • Asking the same model whether its extraction is correct, instead of checking against the source or with code.
  • Reviewing only a handful of documents and concluding the error rate is zero.

Check yourself · 2 of 3

Why should an extraction schema allow null for each field?

Choose one answer

Check yourself · 3 of 3

An invoice extraction has subtotal 900.00, tax 180.00 and total 1,180.00. What does a sum check show?

Choose one answer

Practice items, not counted towards your mastery.

Start here