← All case studies

Finance operations

Invoice intake: from PDF to checked ledger entry

Vendor invoices are read by an AI model and then verified by six checks in plain code before anything is posted. On the four test invoices it flagged a total that was $190 too high, and running any invoice twice is blocked as a duplicate.

Reference build, running live on this site. The same design applies to a client's accounts-payable process.

6

automatic checks per invoice

$190

overcharge flagged on the test invoice

4 of 4

test invoices routed correctly

  1. 1

    Invoice arrives

    PDF, photo or scan

  2. 2

    Extraction

    Claude fills a fixed schema

  3. 3

    Validation

    6 checks in plain code

  4. 4

    Routing

    Posted, or sent to review with a reason

How the automation works, step by step

The problem

In most small finance teams, someone opens each vendor invoice and types it into the accounting system: vendor, invoice number, dates, line items, VAT and bank details. It takes a few minutes per invoice, and the typing is the easy part.

The expensive mistakes are the ones nobody checks for: a total that doesn't match its line items, a mistyped IBAN, or the same invoice paid twice because it arrived by email and by post.

What I built

The pipeline has three stages. Each one does a single job, and each can be tested on its own.

  • Extraction. Claude, an AI model from Anthropic, reads the document and fills in a fixed form. It is instructed to copy what is printed, even when the numbers look wrong, and to leave a field empty if it isn't on the page. It handles scanned documents with OCR errors, European date and decimal formats, and line items in languages other than English.
  • Validation. Plain TypeScript, no AI. Line items must add up to the subtotal, tax must match the stated rate, subtotal plus tax must equal the total, the IBAN's built-in check digits must be valid (ISO 13616), the due date must follow the issue date, and the vendor and invoice number must not already be in the ledger. One-off visitor uploads have no ledger to compare against, so they skip the duplicate check.
  • Routing. If every check passes, the invoice is approved and posted. If any check fails, it goes to a review queue with a one-line explanation, for example: "Subtotal + tax = $3,721.94 but document claims $3,911.94".

Why the model doesn't do the checking

Language models are good at reading messy documents and bad at guaranteeing arithmetic. So the model only reads, and plain code with fixed rules decides whether the result can be trusted. When a check fails, you can see exactly which rule failed and why. Nothing is approved on the model's word alone.

Results on the test set

The demo ships with four invoices covering common accounts-payable problems: foreign formats, bad scans, arithmetic errors and duplicates.

  • A clean UK SaaS invoice: extracted and approved.
  • A German invoice with 19% VAT and DD.MM.YYYY dates: extracted, formats normalised, approved.
  • A poor scan from a Dutch logistics company where OCR turned zeros into O's and ones into l's, including inside the IBAN: in the recorded run, extracted correctly and approved.
  • A US office-supplies invoice whose printed total is $190 higher than its line items and tax: flagged for review before payment.
  • Running any of these a second time is blocked as a duplicate.

Adapting it for a client

In a client setup, invoices arrive from a shared inbox or a Drive folder instead of a demo page, and approved entries post to the accounting system through its API. The checks are extended with the client's own rules, for example matching against open purchase orders or a list of approved vendor bank accounts.

Built with

Next.js route handlers, Claude structured outputs, Zod schemas, TypeScript validators.