cd /news/ai-tools/why-llm-3-way-invoice-matching-doubl… · home › topics › ai-tools › article
[ARTICLE · art-177995] src=dev.to ↗ pub= topic=ai-tools verified=true sentiment=· neutral

Why LLM 3-Way Invoice Matching Double-Counts Short Deliveries (And the Excel Formula That Fixes It)

A developer built a deterministic 3-way invoice matching method that fixes two common LLM arithmetic failures: price variance computed on invoiced quantity instead of received quantity, which double-counts short deliveries, and parsers treating unsigned vendor packing slips as accepted inventory. On a synthetic case (PO-7416, GRN 9906, Invoice BX-118, $1,224.00 billed), the corrected split reconciles to $0.00 across supported, short-delivery, price-variance and freight-cap buckets. The developer published a four-sheet Excel workbook with a Buyer-Signed? SUMIFS gate and a generator script on GitHub.

recommendation

When an LLM splits invoice variances, recompute each bucket algebraically and check the sum reconciles to the invoice total, and filter receiving rows to buyer-signed entries before matching.

more in playbook: Verifying model output
by read3 min views2 publishedNov 29, 2026

When you drop a purchase order, a receiving log, and a supplier invoice into a general-purpose LLM and ask "how much should we hold back?", the output usually looks reasonable until you add the columns up.

In our testing on a synthetic 3-way match case (PO-7416, GRN 9906, Invoice BX-118, total billed $1,224.00), the most common failure was not OCR. It was arithmetic. Specifically, two bugs showed up over and over again when a single invoice combined a short delivery, a unit price increase, and excess freight.

Suppose a line item has:

Q_p at PO unit price P_p Q_r Q_i at invoiced unit price P_i When Q_i > Q_r (short delivery) and P_i > P_p (price increase) happen on the same line, a naive calculation does this:

Short Delivery = (Q_i - Q_r) * P_i
Price Variance = Q_i * (P_i - P_p)   <-- wrong: uses Q_i instead of Q_r

If you sum Supported + Short Delivery + Price Variance, you overshoot the invoice total by (Q_i - Q_r) * (P_i - P_p). You charged the supplier for a price increase on units you already excluded for not being delivered.

The clean algebraic split that reconciles to $0.00 is:

Supported Amount   = Q_r * P_p
Short Delivery     = (Q_i - Q_r) * P_i
Price Variance     = Q_r * (P_i - P_p)

Check the sum:

Q_r * P_p + (Q_i - Q_r) * P_i + Q_r * (P_i - P_p) = Q_i * P_i

Every dollar of the billed line lands in exactly one bucket.

The second failure happens before the math even starts. Suppliers often attach their own packing slip or shipping confirmation to an invoice PDF. If a parser reads every quantity document indiscriminately, it treats an unsigned vendor slip as accepted inventory.

In a spreadsheet, you can block this structurally by adding a Buyer-Signed? column (Yes / No) to the receiving log and wiring it directly into SUMIFS:

=SUMIFS('Receiving Log'!$E$2:$E$100, 'Receiving Log'!$B$2:$B$100, A2, 'Receiving Log'!$G$2:$G$100, "Yes")

Any row marked No contributes 0 to accepted received quantity, so unverified packing slips never silently clear a short-delivery hold.

Freight lines rarely have a quantity variance, so they get skipped in basic SKU-matching scripts. A simple line-level cap check catches it:

=MAX(0, Billed_Freight - PO_Freight_Cap)

Running all three checks on the synthetic PO-7416 / GRN 9906 / Invoice BX-118 pack splits the $1,224.00 invoice cleanly with a $0.00 reconciliation check (=ROUND(Invoice_Total - Supported - Disputed, 2)):

Bucket Amount Rule
Supported by current records $914.00 Q_r * P_p + freight within PO cap
Short delivery (unreceived / unsigned) $216.00 (Q_i - Q_r) * P_i
Price increase on received units only $64.00 Q_r * (P_i - P_p)
Freight above written cap $30.00 MAX(0, Billed - Cap)
Invoice Total $1,224.00 Variance check: $0.00

I put the 4-sheet workbook (PO, Receiving Log, Vendor Invoice, and 3-Way Variance Audit, with formulas and the Buyer-Signed? SUMIFS gate) plus its generator script on GitHub so you can inspect the formulas or adapt them for your own AP reviews:

If you need to pull the line items and page-level quotes out of scanned PDFs before running the math, I also built a small web tool around this exact deterministic audit split: https://apdispute.com/invoice-dispute-evidence-audit (uses the same synthetic case as a no-login sample).

If your team handles partial shipments with prior invoices already paid against the same PO, I would be curious how you track cumulative prior billing in Excel without turning the sheet into a maintenance headache.

── more in #ai-tools 4 stories · sorted by recency
── more on @github 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/why-llm-3-way-invoic…] indexed:0 read:3min 2026-11-29 · —