Working Proof · PDF Invoices → Structured JSON & Reconciliation

Stop copying invoice PDFs by hand—and catch reconciliation errors before they hit your books.

Manual data entry and unverified OCR pipelines silently push broken totals, misparsed regional dates, and unitemized surcharges into accounting sheets and ERPs. This sample run parses three multi-currency invoice layouts into strict JSON and enforces a deterministic math check on every document.

Why manual invoice entry and unchecked extraction fail

FAILURE 01

Hours lost to manual PDF copy-paste

Finance and operations teams open supplier PDFs one by one and re-type invoice numbers, dates, currencies, VAT lines, and itemized rows into spreadsheets or ERPs—with inconsistent US/EU date formats causing silent misfiling.

FAILURE 02

Unchecked reconciliation errors slip into accounting

When a vendor omits a fee from line items, miscalculates VAT, or an OCR pass drops a digit, neither manual entry nor naive LLM extraction verifies whether sum(line_items) + VAT actually equals the stated total.

FAILURE 03

Broken records discovered only at month-end close

Without an automated math gate before writing to Airtable, QuickBooks, Xero, or an ERP, one unitemized £50.00 discrepancy sits unnoticed until bank reconciliation stalls weeks later.

How it works: rule-based extraction + deterministic reconciliation

Deterministic field & table extraction

Parses vendor name, invoice number, issue date, currency, VAT/tax, stated total, and itemized rows across varied vendor templates into a strict schema: {vendor, invoice_no, date_iso, currency, total, vat, line_items[]}.

ISO-8601 dates & exact Decimal math

Normalizes mixed regional date strings (Nov 04, 2026; 12/11/2026; 18 Nov 2026) to YYYY-MM-DD and parses all currency values using exact Decimal arithmetic so floating-point rounding drift never corrupts totals.

Two-level reconciliation gate

Verifies every individual line item (qty × unit_price == amount) and then checks invoice balance (sum(line_items) + vat == stated_total) down to the cent.

Automatic flag & human-in-the-loop routing

Balanced invoices pass straight through as OK. Any non-zero delta sets status=FLAGGED with the exact discrepancy and currency, halting auto-posting so a human reviews only exceptions.

Output fieldTypeSample valueExtraction & check rule
vendorstring"Northstar Cloud Infrastructure Inc."Extracted from explicit Vendor/Supplier label or top issuer header
invoice_nostring"INV-2026-1042"Matched across Invoice No / Invoice # / Invoice Number labels
date_isostring (ISO-8601)"2026-11-12"Normalized from US, EU (DD/MM/YYYY), and UK text formats to YYYY-MM-DD
currencystring (ISO-4217)"USD" | "EUR" | "GBP"Explicit Currency header or symbol fallback ($, €, £)
line_items[]array<object>{description, qty, unit_price, amount}Each line validated for qty * unit_price == amount via Decimal
vat & totalnumber (2 dp)vat: 304.0, total: 1904.0Reconciled with sum(line_items.amount) + vat == total; delta != 0 flags record

Real execution output on 3 sample invoices

Executed directly with python3 scripts/pdf_extract_demo.py (Python 3 standard library only, zero external packages). The sample batch covers three invoice layouts in USD, EUR, and GBP: two balanced invoices (0% and 19% VAT) and one intentionally unbalanced invoice (KA-2026-0391) where the printed total exceeds line items + 20% VAT by +50.00 GBP.

Invoices processed

3

Reconciled (OK)

2

Flagged for review

1

Mismatch caught

+50.00 GBP

Extracted invoice table & reconciliation result

Invoice NoVendorDate (ISO)CcyLinesLines SumVATStated TotalExpectedDeltaStatus
INV-2026-1042Northstar Cloud Infrastructure Inc.2026-11-04USD31170.500.001170.501170.500.00OK
RW-88219RheinWerk Logistics GmbH2026-11-12EUR21600.00304.001904.001904.000.00OK
KA-2026-0391Kestrel Advisory Ltd2026-11-18GBP22150.00430.002630.002580.00+50.00FLAGGED

Reconciliation check outcome (per invoice)

OKINV-2026-1042Northstar Cloud Infrastructure Inc.
balanced: line_items_sum (1170.50) + vat (0.00) == total (1170.50)
OKRW-88219RheinWerk Logistics GmbH
balanced: line_items_sum (1600.00) + vat (304.00) == total (1904.00)
FLAGGEDKA-2026-0391Kestrel Advisory Ltd
total mismatch: line_items_sum (2150.00) + vat (430.00) = 2580.00 != stated total (2630.00), delta=+50.00 GBP

Structured JSON output (exact script payload)

schema: vendor · invoice_no · date_iso · currency · total · vat · line_items[]
[
  {
    "vendor": "Northstar Cloud Infrastructure Inc.",
    "invoice_no": "INV-2026-1042",
    "date_iso": "2026-11-04",
    "currency": "USD",
    "total": 1170.5,
    "vat": 0.0,
    "line_items": [
      {
        "description": "Dedicated Compute Cluster (us-east)",
        "qty": 2,
        "unit_price": 420.0,
        "amount": 840.0
      },
      {
        "description": "Managed PostgreSQL Storage (500 GB)",
        "qty": 1,
        "unit_price": 195.5,
        "amount": 195.5
      },
      {
        "description": "Automated Offsite Backups",
        "qty": 3,
        "unit_price": 45.0,
        "amount": 135.0
      }
    ],
    "reconciliation": {
      "line_items_sum": 1170.5,
      "expected_total": 1170.5,
      "stated_total": 1170.5,
      "delta": 0.0,
      "status": "OK",
      "flagged": false,
      "reasons": [
        "balanced: line_items_sum (1170.50) + vat (0.00) == total (1170.50)"
      ]
    }
  },
  {
    "vendor": "RheinWerk Logistics GmbH",
    "invoice_no": "RW-88219",
    "date_iso": "2026-11-12",
    "currency": "EUR",
    "total": 1904.0,
    "vat": 304.0,
    "line_items": [
      {
        "description": "Cross-Border Pallet Freight (DE-NL)",
        "qty": 4,
        "unit_price": 310.0,
        "amount": 1240.0
      },
      {
        "description": "Customs Clearance Handling",
        "qty": 2,
        "unit_price": 180.0,
        "amount": 360.0
      }
    ],
    "reconciliation": {
      "line_items_sum": 1600.0,
      "expected_total": 1904.0,
      "stated_total": 1904.0,
      "delta": 0.0,
      "status": "OK",
      "flagged": false,
      "reasons": [
        "balanced: line_items_sum (1600.00) + vat (304.00) == total (1904.00)"
      ]
    }
  },
  {
    "vendor": "Kestrel Advisory Ltd",
    "invoice_no": "KA-2026-0391",
    "date_iso": "2026-11-18",
    "currency": "GBP",
    "total": 2630.0,
    "vat": 430.0,
    "line_items": [
      {
        "description": "Operations Audit & Process Mapping",
        "qty": 12,
        "unit_price": 125.0,
        "amount": 1500.0
      },
      {
        "description": "ERP Data Migration Workshop",
        "qty": 1,
        "unit_price": 650.0,
        "amount": 650.0
      }
    ],
    "reconciliation": {
      "line_items_sum": 2150.0,
      "expected_total": 2580.0,
      "stated_total": 2630.0,
      "delta": 50.0,
      "status": "FLAGGED",
      "flagged": true,
      "reasons": [
        "total mismatch: line_items_sum (2150.00) + vat (430.00) = 2580.00 != stated total (2630.00), delta=+50.00 GBP"
      ]
    }
  }
]

Verbatim stdout summary & assertions

3 processed · 2 OK · 1 FLAGGED · exit 0
=== Extracted Invoice Summary & Reconciliation Check (3 sample invoices) ===
| Invoice No | Vendor | Date (ISO) | Currency | Lines | Lines Sum | VAT | Stated Total | Expected | Delta | Status |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| INV-2026-1042 | Northstar Cloud Infrastructure Inc. | 2026-11-04 | USD | 3 | 1170.50 | 0.00 | 1170.50 | 1170.50 | 0.00 | OK |
| RW-88219 | RheinWerk Logistics GmbH | 2026-11-12 | EUR | 2 | 1600.00 | 304.00 | 1904.00 | 1904.00 | 0.00 | OK |
| KA-2026-0391 | Kestrel Advisory Ltd | 2026-11-18 | GBP | 2 | 2150.00 | 430.00 | 2630.00 | 2580.00 | +50.00 | FLAGGED |

Summary: processed=3, reconciled_ok=2, flagged_for_review=1

=== Reconciliation Audit Log ===
[OK] INV-2026-1042 (Northstar Cloud Infrastructure Inc.): balanced: line_items_sum (1170.50) + vat (0.00) == total (1170.50)
[OK] RW-88219 (RheinWerk Logistics GmbH): balanced: line_items_sum (1600.00) + vat (304.00) == total (1904.00)
[FLAGGED] KA-2026-0391 (Kestrel Advisory Ltd): total mismatch: line_items_sum (2150.00) + vat (430.00) = 2580.00 != stated total (2630.00), delta=+50.00 GBP

Assertions passed: 3 invoices extracted -> 2 OK (USD, EUR), 1 FLAGGED (KA-2026-0391, +50.00 GBP mismatch caught).

Want PDF invoice extraction and reconciliation wired into your stack?

Share 3–5 anonymized sample PDFs and your destination schema (Airtable, Google Sheets, Postgres, or ERP). We scope every build on a short call and send a tailored quote in USD.