Line items extract cleanly but they do not sum to the invoice total
In short
Compute the whole chain, not the sum of the lines: quantity times unit price to line net, lines to a document total, document-level allowances and charges, tax per rate, then prepaid amounts to the amount due. The residual identifies the fault: a ratio to the subtotal near the rate over one plus the rate means the lines were tax-inclusive and the total was not.
Key takeaways
- The residual as a proportion of the subtotal identifies the fault faster than reading the page does.
- A residual matching the rate over one plus the rate is a tax-inclusive line set, not a misread digit.
- Rounding is the only residual you may accept, and it is bounded by the number of lines.
- A failed arithmetic check must block posting; lowering a confidence score lets it through anyway.
- Never write the difference to a rounding account — that converts a detected defect into a permanent one.
The exception says invoice line items do not match total. Extraction is the usual suspect and is usually innocent: every field on the page was read correctly, and the arithmetic still fails because the document's own totals were never computed the way your validator computes them. Before opening the PDF, divide the difference by the extracted subtotal. That single ratio separates a tax convention problem from a missing charge line from a lost page, and it takes a second.
It helps to know that the chain is specified rather than conventional. The European semantic standard for electronic invoicing, as implemented in the Peppol BIS Billing 3.0 specification, defines the whole sequence — the sum of line net amounts, document-level allowances and charges, a tax breakdown per category and rate, the total with tax, prepaid amounts, and an explicit rounding adjustment on the amount due. Structured invoices carry those as separate values. A PDF prints some of them, implies others, and leaves your validator to reconstruct the rest.
Compute the chain, not the sum
- Line net for every row. Quantity times unit price, adjusted by any line-level discount or charge. Where the row prints both a unit price and an extended amount, take the extended amount and use the multiplication as a check on it, not the other way round.
- Sum the line nets to a document line total. Compare it against the printed subtotal before going any further; if these already disagree, the fault is in the table and nothing further down the chain will diagnose it.
- Apply document-level allowances and charges. Settlement discounts, delivery, freight, insurance, surcharges and handling appear beneath the table on most layouts and outside it on all of them.
- Compute tax per rate, not once. An invoice with lines at 2 different rates has 2 taxable bases, and a single rate applied to the whole subtotal will be wrong whenever the mix is not uniform.
- Add tax to reach the gross, then subtract prepaid amounts and apply any stated rounding adjustment to reach the amount due. The amount due and the invoice total are different fields and a validator that treats them as one will fail every invoice carrying a deposit.
- Record the residual at each step, not a single pass or fail. Knowing that the chain broke between the line total and the taxable total is most of the diagnosis.
Divide the difference by the subtotal before opening the page
| Residual signature | Usual cause | Confirming check |
|---|---|---|
| Ratio to subtotal equals the rate divided by 1 plus the rate | Lines are tax-inclusive, the total is tax-exclusive, or the reverse | Recompute the lines as inclusive; if the chain closes exactly, that is the answer |
| Equals a named amount printed beneath the table | A freight, insurance, handling or surcharge line outside the table | The residual matches that printed figure to the cent |
| Negative, and a round proportion of the subtotal | A document-level discount or settlement allowance not captured | The page shows a percentage near the total; the residual over the subtotal reproduces it |
| Small, and no larger than 0.01 times the line count | Per-line rounding accumulating against a total rounded once | Recompute at full precision and round only at the end; the residual disappears |
| Equals a plausible contiguous block of lines | A continuation page dropped, or the last rows of the table lost | Page-of-n marker against page count, and the last captured row against the page footer |
| Large, and equals the sum of quantity times price minus the extended amounts | Unit price captured where the extended amount was meant | Every affected row has quantity greater than 1 and a residual proportional to it |
One signature is not on that list because it is not really an arithmetic fault. A residual that is a factor of 1,000 out, or that turns 1.234,56 into something a hundred times larger, is a separator convention misread — the fault that only damages documents from particular sources, described in dates and amounts wrong for one client's suppliers. Check it first when the residual is absurd rather than merely wrong.
Tax-inclusive lines against a tax-exclusive total
This is the single most common cause and the one most often misdiagnosed as a reading error. Retail-facing suppliers print line amounts with tax included; business-facing suppliers usually do not; some print both and label neither clearly. A validator that assumes exclusive lines will fail every invoice from the first group by exactly the tax fraction, and a validator that assumes inclusive lines fails the second group the same way in the opposite direction.
The fix is not a smarter parser. It is a captured property: record on the supplier record whether that supplier's lines are tax-inclusive, default it to unknown, and let the arithmetic itself resolve unknown by testing both readings and accepting the one that closes exactly. That inference is only durable if the supplier record is stable, which is a real dependency — where one supplier arrives under six different names, a property learned on one name protects a sixth of their invoices.
The charge that never appears in the table
Table recognition finds tables. Freight, insurance, packaging, fuel surcharges, environmental levies, settlement discounts and deposit deductions are typically printed as loose label-and-amount pairs beneath the table, sometimes in a second column beside the totals block, occasionally in the footer. They are part of the arithmetic and outside the structure your extractor was looking at.
Extract the totals block as its own object with its own field set — subtotal, each named adjustment, taxable amount, tax per rate, gross, prepaid, amount due — rather than treating it as the last few rows of the table. That separation is what makes the residual interpretable: when the chain fails, you can say which of those fields is missing rather than only that something did not add up.
Rounding is the only difference you may accept
The standard's own rules are the right guide here. Peppol BIS Billing 3.0 requires document-level amounts to be rounded to 2 decimals and line net amounts likewise, and states that results of calculations involving already-rounded amounts are not themselves subject to further rounding. It also provides an explicit rounding adjustment on the amount due — an admission, in the specification itself, that the chain does not always close to the cent.
So set a tolerance that is bounded by structure rather than by taste: no more than 0.01 per line, and never a flat allowance that scales with the invoice value. A 40-line invoice may legitimately differ by 0.40 through per-line rounding; a 4-line invoice may not differ by 0.40 by any legitimate route. A tolerance expressed as a percentage of the total is the version of this rule that silently swallows real faults on large invoices.
A failed arithmetic check blocks; it does not lower a score
Confidence scores measure how sure the reader is about what a character was. Arithmetic measures whether the document is internally true. They are different quantities, and folding the second into the first is how invoices with impossible totals reach a ledger: a field read with 0.99 confidence in a document whose chain fails by 240.00 still averages into a healthy-looking score, and an approval threshold set on that average lets it through.
Keep them separate in the record and separate in the gate. Field confidence routes to review; a broken chain blocks posting outright and produces a reason naming the step that failed and the residual. That queue then needs an owner and a deadline, because an exception queue with neither becomes an archive — and the dates it has to be empty by come from the filing calendar, which is its own moving target, as a deadline calendar that survives rule changes sets out.
A confidence score says how well the page was read. The arithmetic says whether the page can be true. Only one of them should be allowed to stop a posting.
Sometimes the arithmetic is fine and the document is not an invoice
A recurring, unresolvable chain failure across documents from one source is often a routing fault rather than an extraction one. Statements of account list open invoices and total them without ever being an invoice; proforma invoices, delivery notes with prices, quotations and credit notes all present a table and a total, and none of them obeys the invoice chain. Applying invoice arithmetic to a statement of account produces a residual every time and no amount of parser work will close it.
So make the arithmetic result feed back to classification instead of only to review. A document that fails the chain by exactly the sum of its own lines is a strong signal it was never an invoice, which is the routing argument in routing an incoming client file to the right handler. Wiring validation results back into routing is a small piece of product build work and one of the higher-yield ones in extraction and classification of source documents, inside the accounting and tax systems we build.
Frequently asked questions
Short answers to the follow-ups this page tends to raise.
Why do extracted invoice line items not add up to the invoice total?
Most often because the lines and the total use different tax conventions, not because a figure was misread. Divide the residual by the subtotal: a ratio equal to the tax rate divided by 1 plus that rate means the lines are tax-inclusive and the total is not. The other frequent causes are a charge printed outside the table, an uncaptured document-level discount, per-line rounding, and a dropped continuation page.
What tolerance should an invoice arithmetic check allow?
Bound it by the number of lines, not by the invoice value: no more than 0.01 per line. A 40-line invoice can legitimately differ by 0.40 from per-line rounding, while a 4-line invoice cannot. A percentage-of-total tolerance looks reasonable and quietly permits large absolute differences on large invoices, which is exactly where a systematic fault does the most damage.
Should a failed totals check lower the confidence score or block the invoice?
Block it. Confidence describes how certain the reader is about characters; arithmetic describes whether the document is internally consistent. Blending them lets a well-read but impossible invoice pass an averaged threshold. Route field-level uncertainty to review, and stop a broken arithmetic chain from posting at all, with a reason naming the step that failed and the size of the residual.
Can the pipeline just post the difference to a rounding account?
No. It balances the entry and destroys the evidence: your ledger now disagrees with the supplier's by an unexplained amount, and a systematic fault that would have been obvious as a pattern is dispersed across hundreds of small postings. Rounding differences within a per-line tolerance need no posting at all; anything larger is a defect to be fixed at the source, not absorbed.
- document extraction
- invoices
- validation
- data quality
The work behind this page
Builds from our portfolio that this page draws on.
AP Copilot
An AI accounts-payable copilot that reads invoices, matches them to POs, and routes clean approvals
FintechNotewell
An AI meeting assistant that records and transcribes every meeting, extracts the decisions and action items, assigns owners and due dates, and tracks follow-through until it's done.
Productivity AIAskVault
An AI internal knowledge-search platform that answers employee questions from your own docs — grounded in citations, with knowledge gaps surfaced and deflection tracked.
Productivity AIRead next
- Extracted statement: closing balance does not equal opening plus movementsA bank statement proves its own completeness. Foot it page by page, and the size and sign of the difference tell you which row was dropped, duplicated, inverted or invented.diagnostic
- Dates and amounts come out wrong, but only for one client's suppliersA locale fault cannot corrupt every document, which is exactly why it survives. Sample the ambiguous cases only, sliced by supplier, and the fault appears at once.diagnostic
- A credit note is not a negative invoice: where the sign really livesModel it as an invoice with a minus in front and three things break: allocation, tax reporting, and every aging report that reads the ledger afterwards.definition
- A two-hundred-page client scan splits into the wrong number of documentsBoundary errors are wildly uneven across document types, so an overall accuracy figure hides them. Count documents in against documents out, per type, and fix the cause where the pages are produced.diagnostic
- Half the client bank statements will not open in the pipeline at allA pile of failed jobs at the first step is four different problems wearing one error message. Classify by failure class before anyone retries, re-requests or asks a client for a password.diagnostic
- One supplier arrives under six names, and none of them match the ledgerA supplier's name is the least stable field on its invoice. Match on the registration number, the remittance account and the address, and let name similarity break ties nothing else can.diagnostic
Working on something in this space?
Tell us where you are in a sentence or two. We'll tell you honestly whether we're the right team, and what a sensible first slice of the work looks like.
Start the conversation