I m building an invoice extraction API, and part of it checks that the extracted amounts add up. My first version allowed a cent of difference everywhere. That was wrong in both directions: it flagged correct invoices and let some errors through.
Three things I learned:
A check needs three answers, not two: it adds up, it doesn t, or it can t be decided. If a number is missing, don t guess it to make the check pass.
Tax needs rounding in any direction. Issuers round tax down, or take it out of a price that already includes it. A price of 691.34 including 10% tax carries 62.84 of tax once rounded down, leaving 628.50. But 628.50 10% is exactly 62.85, so a strict check fails a correct invoice by a cent.
The arithmetic is the easy part. Every rule depends on a question the numbers can t answer: does the subtotal already include tax? Do you have every line? You can t decide that by checking which equation fits, or every check passes by construction.
I wrote up all the rules, with Python and TypeScript you can copy: https://temlavo.com/blog/validat...
I am launching Temlavo, an invoice extraction API, and I am especially interested in hearing from developers and automation consultants who have built invoice workflows. Is the painful part OCR, inconsistent layouts, line items, review logic, duplicates, downstream accounting integration or something else?
Temlavo is an invoice extraction API for developers and automation teams. It turns PDFs and images into structured accounting JSON with vendor/customer data, totals, taxes, and line items. Instead of stopping at extraction, it adds consistency checks, duplicate signals, and configurable review rules, returning completed, needs_review, or failed outcomes your workflow can act on. Use it through TypeScript SDK/CLI, raw HTTP, or n8n.