Back to Blog
Build in Public

Day 6 of Document Extraction Workbench: The quote says 90.00 and the value says 9.00

Day 6 closes the hole from Day 5. Invoice 3 stores 9.00. Its quote is Total: 90.00, and those words are on the page. The old check passed. The new check flags it. The saved total stays 9.00.

Document Extraction Workbench: an invoice becomes a structured record with a source page
By Brian Shimkus 5 min read

The short version

Day 5 checked that a quote appears on the page. That check can pass while the number in the value and the number in the quote are different.

Day 6 compares those two numbers. I still did not call a model. The score on the three development invoices stays 2 out of 3 for the total, because the check asks a person to look. It does not rewrite 9.00 into 90.00.

The check

For the total only, the quote is split into words. Each word is sent through normalize. Words that are not amounts are skipped. The cleaned total has to be one of the amounts found in its own quote.

if name == "total" and field.quote and values[name]:
    quoted = []
    for word in field.quote.replace(":", " ").split():
        try:
            quoted.append(normalize("total", word))
        except ValueError:
            continue
    if values[name] not in quoted:
        issues.append("total: value does not match quote")

Total: 90.00 becomes the amount 90.00. The saved value is 9.00. Those are not the same, so the issue is total: value does not match quote and needs_review is true.

normalize is what makes 125 and 125.00 match. A plain text search would treat them as different strings.

The old test expected this case to pass. I kept the test and changed the assertion. Deleting it would have hidden the hole. Eight tests passed.

What this still misses

A quote that contains both numbers can hide the wrong one. Subtotal: 9.00 Total: 90.00 includes 9.00, so a saved total of 9.00 would match a number in the quote. The check does not know which number is the final total.

needs_review: true sends the record to a person. The cleaned value in the report is still 9.00. The development score stays 2 correct totals out of 3 until the saved answer itself is fixed.

What I set up on Day 6

Day 6 was one commit:

feat: flag a total that does not match its quote

Frequently asked questions

Why did 9.00 pass on Day 5?

The quote check searched for Total: 90.00. Those words are on the page. It did not compare 9.00 with 90.00.

What does the new issue mean?

The cleaned total is not one of the amounts written in that field's quote.

Does the check correct the total?

No. It flags the record. A person still has to decide what the total should be.

Did a model read the invoice today?

No. The wrong 9.00 came from the saved practice answer. The next day is the first live call.

Next up

The next day is the first live call to a model. I will write about what I learn as I go, including the mistakes.

Related: Day 5 of Document Extraction Workbench: A quote on the page is not proof the total is right