Liveautomationhitlfinance

invoice-pipeline

Email inbox to accounting system: PDF invoices in, validated line items out. Humans review the weird ones.

invoice-pipeline preview

§ 01 · Overview

An invoice ingestion pipeline that reads PDF invoices from a folder, extracts structured fields via Claude's native PDF handling, validates against rules (VAT number format, subtotal-plus-VAT-equals-total math, duplicate detection), routes every invoice through a human review queue, and appends approved records to a CSV output. Designed for the ambiguous middle of invoice processing: multi-page invoices, credit notes with negative totals, foreign currency, and VAT edge cases.

§ 02 · Estimated impact

£12,000-£45,000/yr per finance team
for SMB and mid-market finance teams currently keying invoices manually or paying an OCR bureau
Basis: An AP clerk keys 800-1,500 invoices per month at 3-5 minutes each, or 60-125 hours per month. At £22/hr fully-loaded that represents £16,000-£33,000/yr in data-entry cost. Add £3,000-£8,000/yr in duplicate-payment or PO-mismatch errors that a rushed clerk misses. Automated extraction with human-in-the-loop review removes approximately 90% of the volume from the clerk's queue while retaining review on the 10% requiring judgement.

§ 03 · Architecture

  1. 01

    Reads every PDF from a configured folder (v0.1) or from a Gmail/Outlook watcher (roadmap v0.2). Each file is passed to Claude's native PDF handling with a strict JSON schema covering supplier, invoice number, VAT number, dates, currency, subtotal, VAT total, total, and per-line description/quantity/unit-price/VAT-rate. Confidence is reported per extraction.

  2. 02

    Validation is rules-based: missing supplier or invoice number, VAT number format, subtotal-plus-VAT-equals-total within a configurable tolerance, line-item versus subtotal drift, and low-confidence extraction. A duplicate store keyed by (supplier, invoice_number) prevents re-processing.

  3. 03

    Every extracted invoice is routed to the review queue provided by hitl-review. A preview markdown file is written to the drafts folder immediately for out-of-band inspection.

  4. 04

    On approval, the invoice is appended to the output CSV with one row per invoice and line items serialised as an embedded JSON column. The duplicate store is updated so a future run recognises the same invoice.

Stack

PythonFastAPIGmail/Outlook Graph APIsClaude (vision + extraction)PostgresReact (review queue UI)Xero/QBO/Sage adapters

§ 04 · Positioning

Invoice OCR products either output raw text with no downstream reasoning, or bundle a full accounting UI you're expected to adopt. The gap is the middle layer: rules-based validation, a human-in-the-loop review UX, and pluggable output.

AlternativeTrade-off
Dedicated OCR / AP SaaS platforms£200-£1,500/mo minimum spend, vendor-owned data, and coupling to the vendor's accounting UI. Sensible for a 500-person AP team; disproportionate for the 5-15 invoice/day SMB where this problem is most common.
Zapier or n8n with a generic OCR APIAdequate for well-formed single-page invoices. Degrades on multi-page invoices, credit notes, foreign VAT, and any ambiguity — because human-in-the-loop review is not part of the design. The result is faster processing of unreliable data.
Manual data entry by a junior accountantSlow and error-prone at scale, though essential for genuinely ambiguous invoices. The pipeline is built to route only the ambiguous cases to a human, not to replace judgement altogether.

§ 05 · Frequently asked

How does invoice-pipeline detect duplicate invoices?

A JSON-file duplicate store keyed on the normalised (supplier, invoice_number) pair. Every approved invoice is recorded on push to CSV, so a subsequent run against the same PDF (or a re-sent one from the supplier) is flagged as duplicate_invoice before extraction spend is incurred. Casing is normalised so 'Acme Ltd · INV-1' matches 'acme ltd · inv-1'.

What happens when Claude's PDF extraction confidence is low?

A low_extraction_confidence warning is added to the invoice's issue list at any confidence below 0.7, and the invoice is queued for human review regardless. Nothing silently drops — every invoice reaches the reviewer with its full extraction and confidence surfaced.

Does invoice-pipeline push directly to Xero or QuickBooks?

Not in v0.1. Approved records are appended to a CSV output that imports cleanly into any accounting system. Direct-push adapters for Xero, QuickBooks, and Sage are on the roadmap for v0.3, all routed through the human review queue.

Availability

Available now. Review the source, try it in your stack, or discuss integration.

Follow along

Build notes and updates are published in the Notes. Or check GitHub for release notes and open issues.