Architecture Note · Finance & Legal

Automated AP & 3-Way Invoice Matching: Deterministic Tolerance Math and Dual-Signoff Gates

Why LLM invoice extractors cannot own accounts payable controls—and how SHA-256 deduplication, Decimal tolerance rules, and tiered CFO sign-offs safeguard ERP disbursements.

The Operational Problem: Unit-Price Creep, Unreceived Goods, and Duplicate Bills

Multi-entity finance teams processing supplier invoices across NetSuite, SAP S/4HANA, and Xero deal with subtle variances that slip past manual spot-checks: a 2.4% unit-price increase on CNC spindle assemblies in Frankfurt (EUR 1,000 PO vs EUR 1,024 invoice), a 3.8% drift on 6-axis servo actuators in Tokyo billed in zero-decimal JPY, missing Goods Receipt Notes (GRNs), VAT rate mismatches, and resubmitted PDF bills. Approving an invoice without verifying all three legs—Supplier Invoice, Purchase Order, and Goods Receipt Note—turns small line-item drift into permanent cash leakage.

Why Naive AI Invoice Wrappers Fail Financial Audit

Passing PDF invoices directly to an LLM prompt for approval recommendations fails internal controls on three fronts:

  • Floating-point and currency rounding errors: Standard language models hallucinate cross-line sums or misapply zero-decimal currencies like JPY versus two-decimal currencies (USD, EUR, GBP, CAD, SGD), creating penny imbalances that fail ERP batch validation.
  • No stateful duplicate or receipt verification: A stateless prompt comparing an invoice against a PO cannot detect that the same (vendor_id, invoice_number) pair or identical payload SHA-256 digest was already ingested last week, nor enforce a hard block when warehouse receiving has not logged a GRN.
  • Bypassed segregation of duties: Without cryptographic role separation between AP Operations, Corporate Controller, and CFO, an automated wrapper risks releasing high-value disbursements or overriding tax discrepancies without dual sign-off.

The Deterministic Architecture That Fixes It

The Accounts Payable 3-Way Matching engine separates document parsing from deterministic accounting math, deduplication, and tiered authorization.

  1. Multi-format ingestion with SHA-256 deduplication and 1-hour purge: POST /api/invoices/ingest accepts PDF, JSON, and OASIS UBL 2.1 XML payloads using deterministic offline extraction by default (zero external network calls) with optional private openai_compatible mode. It computes SHA-256 payload digests, enforces (vendor_id, invoice_number) uniqueness across non-rejected records with HTTP 409 conflict blocks, and wipes raw temporary uploads after 3,600 seconds via app/wiper.py.
  2. Exact Decimal 3-way match engine: POST /api/invoices/{id}/match compares every invoice line against stored Purchase Orders and Goods Receipt Notes in SQLite (WAL mode) using Python Decimal minor-unit rounding across USD, EUR, GBP, JPY (0 decimals), SGD, and CAD. Configurable price_tolerance_pct, qty_tolerance_pct, and tax_tolerance_pct thresholds emit deterministic statuses—matched, variance_hold, missing_grn, or duplicate_blocked—alongside exact line-item deltas.
  3. Role-based USD-equivalent approval routing: POST /api/invoices/{id}/decision enforces strict authority ceilings using scoped invite tokens with sliding-window rate limits (429 + Retry-After): ap_ops may approve clean matches up to $25,000 USD equivalent but receives HTTP 403 on variance overrides; controller handles variance overrides (requiring a written justification) up to $100,000 USD equivalent and executes stage-1 sign-off on larger bills; cfo completes releases above $100,000 USD and returns HTTP 409 if controller sign-off has not occurred first.
  4. Gated ERP batch export and SLA escalation: GET /api/batches/export formats NetSuite, SAP S/4HANA, or Xero posting batches in JSON or CSV strictly for approved invoices—never exporting holds, missing GRNs, or duplicate blocks—and records every sign-off and vendor-hold action in an immutable audit_log with 24-hour controller escalation tracking.

Operational Takeaway

Automating accounts payable does not mean delegating payment release authority to an AI model. When extraction feeds deterministic Decimal tolerance checks across six currencies, duplicate digests fail closed on 409, and ERP batch generation stays locked until tiered Controller and CFO sign-offs are recorded, AP teams accelerate close cycles while strengthening SOX and audit readiness.

Test 3-way matching on your own POs and invoices

Start with a free 30-minute workflow check. Bring one anonymized supplier batch and tolerance policy to scope a private deployment within one business day.