◇ AI Invoice & Receipt Extractor Python · Claude · OCR · Gmail · Sheets Project Blueprint
Finance Automation

Invoices that file themselves.

It watches the inbox, pulls the attachment, reads the document — scanned or not — and turns it into one clean row with the vendor, the dates, the line items, the tax, and the total. Then it checks its own arithmetic, and anything that doesn't add up is flagged instead of exported.

Below, the path of one invoice, what comes out, and how it's built.
01

The Path of One Invoice

Two ways in, one queue, and a check at the end that decides whether a row is finished or needs a person. The original never leaves the record.

Inbox watched, no upload 📤 Upload for everything else one queue Read text layer or OCR 📄 Extract 12+ fields, structured 📋 Validate does the maths hold? 🔢 totals reconcile One clean row, exported Flagged for review the numbers disagree Originals kept every row links back to the document it came from
you drop a file in runs automatically needs a person

two ways in

inbox attachment → queued automatically
anything else → drag the file in

then, one queue

📄
Read
Straight from the PDF, or OCR for a scan.
📋
Extract
Vendor, dates, line items, tax, total, currency.
🔢
Validate
Do the line items actually add up to the total?
totals reconcile → one clean row, exported
numbers disagree → flagged for review
↓ the original document is kept — every row links back to its source
02

Inside Each Step

01 The inbox is watched

The system connects to a Gmail or Outlook mailbox and keeps watching it. When a message lands with a PDF, JPG, or PNG attached that looks like an invoice or a receipt, it's pulled and queued on its own. This is the step that makes the whole thing hands-free — the alternative is a human remembering to check a folder, and the folder always wins.

Gmail API · Microsoft Graph · attachment detection
📤

02 Or you drop a file in

Not everything arrives by email. Paper that got scanned, a photo of a receipt taken in a car park, a batch someone exported from a portal — all of it can be dragged straight into the web interface. Same queue, same treatment from here on.

web upload · PDF, JPG, PNG, scans
📄

03 Read the document

Documents with a real text layer are read directly, which is fast and lossless. Anything scanned or photographed goes through OCR instead, with image preprocessing first, and comes back as text with its position on the page attached — because on an invoice, where a number sits is half of what tells you what it is.

PyMuPDF · Tesseract OCR · Pillow preprocessing
📋

04 Extract the fields

The text becomes a structured record: vendor, invoice number, invoice date, due date, line items with descriptions and amounts, subtotal, tax and tax rate, total, currency, payment terms. This is where the format chaos gets absorbed — "Net 30" and an actual date are the same field, tax buried in a total is still tax, and anything genuinely ambiguous carries a confidence score rather than a confident guess.

Claude API · structured extraction · confidence scoring
🔢

05 Validate and normalise

Dates get one consistent format, currencies get identified and labelled, and the arithmetic gets checked: line items should sum to the subtotal, and subtotal plus tax should equal the total. When they don't, the record is flagged rather than exported. This is a deterministic rules pass, not a second opinion from the model.

rules engine · reconciliation, dates, currency
📊

06 Export, with the original attached

Each invoice becomes one row — written to a CSV or pushed straight into a connected Google Sheet, with flagged records highlighted so a person knows exactly which handful to look at. The source document is stored alongside the record, so any figure can be traced back to the page it was read from months later, when someone asks.

Google Sheets · CSV · originals in S3 or local store
The check that makes it trustworthy

Arithmetic is the cheapest lie detector there is.

A model can misread a digit on a blurry scan — any extraction system can. What it can't do is make a wrong number add up. Line items that don't sum to the subtotal, or a subtotal and tax that miss the total, catch the error without anyone reading the document. That's why the validation pass is plain deterministic rules: it's the part that has to be right when the reading isn't.

03

What Comes Out

One row per invoice, twelve-plus fields, in the same shape every time regardless of how the vendor laid the page out.

WHO
Vendor and invoice number

The identity of the document — who billed you and their reference for it. What you need to match a payment to a bill, and to spot the same invoice arriving twice.

WHEN
Invoice date, due date, terms

Normalised to one format regardless of how it was written. "Net 30" is resolved to a real date, so a due-date column can actually be sorted.

WHAT
Line items, described and priced

Each line captured with its description and amount rather than collapsed into a single total, which is what makes the record useful for anything beyond paying it.

HOW MUCH
Subtotal, tax, rate, total, currency

Tax is broken out even when the vendor buried it in the total, and the currency is identified rather than assumed — which matters the first time an international invoice lands.

HOW SURE
Confidence, on the fields that earned doubt

Ambiguous fields carry a score and reconciliation failures carry a flag, so a finance team reviews the handful of documents that need it instead of spot-checking all two hundred.

04

Architecture

A model in the middle for reading, deterministic rules on either side of it.

Intake

Gmail API · Microsoft Graph · web upload

Watches a mailbox for attachments and accepts direct uploads for everything that doesn't arrive by email. Both feed one queue.

Reading

Parsing

PyMuPDF · Tesseract · Pillow

Direct text extraction where there's a text layer, OCR with preprocessing where there isn't. Same output either way.

Understanding

Extraction

Claude API · structured output

Turns messy page text into the same set of fields every time, and scores its own confidence where a field is genuinely ambiguous.

Checking

Validation

rules engine · no model involved

Normalises dates and currencies and reconciles the totals. Deterministic by design — this is the layer that catches the reading being wrong.

Export and archive

Google Sheets · CSV · S3 or local originals

One row per document into the sheet or file the business already works in, with flagged rows highlighted, and the source document retained so every figure stays traceable.

05

How It's Built

Six modular blocks. Mailbox, export target, and storage swap per client; the queue and the check don't.

01

Inbox watcher

intake

Spots invoice attachments and queues them.

02

Parser

reading

Text layer when there is one, OCR when there isn't.

03

Extractor

structuring

Page text becomes the same fields every time.

04

Validator

reconciliation

Checks the maths, normalises dates and currency.

05

Exporter

output

One row per invoice, straight into the sheet.

06

Archive

audit trail

Keeps the original beside the record it produced.

06

Stack

Python Gmail API Microsoft Graph PyMuPDF Tesseract OCR Pillow Claude API Google Sheets S3