Paj Digital Labs
All articles
AI & Automation

Automating Invoices and Receipts With AI Without Trusting It With Your Books

Document extraction is one of the most useful AI automations for small businesses — and one of the easiest to get dangerously wrong. A pipeline design that keeps a human on every number that matters.

Paj Digital Labs 3 min read
Robotic gripper sorting components on a laboratory workbench
Editorial illustration · AI & Automation

A small agency I work with was spending around six hours a week typing supplier invoices into their accounting software. Vendor name, date, invoice number, line items, tax, total. It is exactly the kind of work AI document extraction is good at — and exactly the kind of work where a single wrong digit causes a real problem.

The automation we built cut that six hours to about forty minutes. Here is how it is designed so the remaining forty minutes are the right forty minutes.

The pipeline

text
Email inbox / upload
   -> store original file (never modify it)
   -> extract text + layout (OCR if scanned)
   -> LLM extraction into a strict schema
   -> validation rules
   -> review queue (human approves)
   -> post to accounting system

The original file is stored first and kept forever. Every extracted record links back to it. When an accountant asks where a number came from, the answer is one click away.

Extraction schema

json
{
  class="text-code-string">"vendor_name": class="text-code-string">"string",
  class="text-code-string">"invoice_number": class="text-code-string">"string",
  class="text-code-string">"invoice_date": class="text-code-string">"YYYY-MM-DD",
  class="text-code-string">"currency": class="text-code-string">"ISO 4217 code",
  class="text-code-string">"subtotal": class="text-code-string">"number",
  class="text-code-string">"tax": class="text-code-string">"number",
  class="text-code-string">"total": class="text-code-string">"number",
  class="text-code-string">"line_items": [{ class="text-code-string">"description": class="text-code-string">"string", class="text-code-string">"qty": class="text-code-string">"number", class="text-code-string">"unit_price": class="text-code-string">"number" }]
}

Amounts are extracted as strings first and parsed in code. Models occasionally drop or add a digit, and handling currency formats ("1.234,56" versus "1,234.56") is something deterministic code does better than a prompt.

Validation does the heavy lifting

The model is not trusted. The arithmetic is. Every extraction passes through rules like:

  • Line items multiplied out must equal the subtotal (within a small rounding tolerance)
  • Subtotal plus tax must equal the total
  • Invoice date cannot be in the future or more than a year old
  • Invoice number plus vendor must not already exist (duplicate detection)
  • Vendor must match a known supplier, or be flagged as new

| Check | Catches | |---|---| | Arithmetic | Misread digits, missed line items | | Duplicates | Same invoice emailed twice — very common | | Known vendor | Typos, and some fraud attempts | | Date sanity | Day/month swaps on international invoices |

Any failed check sends the record to review with the failing rule highlighted.

The review screen is the real product

Reviewers see the original document on the left and extracted fields on the right, with each field highlighted where it was found on the page. Records that passed every check show a green state and can be approved with one click. Records that failed show exactly which rule broke.

This is where the time saving comes from. Approving a correct extraction takes five seconds. Typing it from scratch took three minutes.

Never auto-post payments

Extraction can be automated. Posting to the books can be automated after approval. Paying an invoice should never be triggered automatically by an AI pipeline. Invoice fraud — fake suppliers, changed bank details — is common, and an automated payment pipeline is a gift to anyone attempting it.

Any change to a supplier's bank details triggers a separate manual verification step, by phone, using a number from your records rather than one from the invoice.

Track accuracy per field

Every time a reviewer corrects a field, log it. After a month you know which fields are reliable and which are not. In our case, totals were nearly always right, line-item descriptions were often slightly off, and dates on a handful of international suppliers were consistently swapped. That told us where to add rules and which vendors to handle with a template.

Data handling

Invoices contain names, addresses, bank details and sometimes personal data. Check your AI provider's data retention terms, avoid sending documents to services that train on inputs, and restrict who can access the original files.

AI extraction is a genuine time saver for any business drowning in paperwork. Just design it so the AI drafts and the rules check — and a human signs off on anything that moves money.

Paj Digital Labs

The engineering journal of Paj Digital Solutions — hosting, server infrastructure and web engineering, written by the people who run the servers.

Related reading