Skip to content

FinancePrototypeEN

Invoice data extraction

Demo prototype: reads synthetic PDF invoices and fills an accounting import file.

Esempi BestIAPublished on 24 November 2026
Maturity
Prototype
Category
Finance
Entry language
English
Published
24 November 2026

01The problem

In this fictional company, invoice data is typed by hand into the accounting software, with frequent mistakes in VAT numbers and totals.

02The solution

PDFs are converted to text, key fields are extracted and validated against simple rules, and a CSV is produced for the accounting import.

The AI core of the project

03Role of AI

A language model extracts structured fields; totals and VAT checksums are verified by code before anything is exported.

04Technical architecture

README.md

InvoiceLens — invoice data extraction

Demo prototype on synthetic PDF invoices.

Overview

Batch tool that turns PDF invoices into an accounting import CSV. The model extracts fields; code verifies totals and VAT numbers.

Pipeline

text
inbox/*.pdf
   |
   v
[pdfplumber] text + tables  --(no text layer)--> [OCR]
   |
   v
[LLM API] -> InvoiceSchema (JSON)
   |
   v
[Validators] VAT checksum, sum(lines) == total, dates, currency
   |                       |
   ok                      fail -> review.csv (with reason)
   v
export/accounting.csv  +  audit.jsonl (field -> page, bbox, text span)

Stack

PartTechnology
RuntimePython 3.12, Typer CLI
PDFpdfplumber
SchemaPydantic v2
AILLM via API

Schema

python
class Line(BaseModel):
    description: str
    quantity: Decimal
    unit_price: Decimal
    vat_rate: Decimal

class Invoice(BaseModel):
    supplier_name: str
    supplier_vat: str          # validated with checksum
    number: str
    issue_date: date
    currency: Literal["EUR"]
    lines: list[Line]
    total: Decimal

Checks

  • abs(sum(line.quantity * line.unit_price * (1 + line.vat_rate)) - total) <= 0.01
  • VAT number checksum per country.
  • Duplicate detection on (supplier_vat, number).

Run

bash
uv run invoicelens extract inbox/ --out export/

05Results and lessons

Results verified by the author

Fields correct on 47 of 50 synthetic invoices in the author's test.

—Images

  • Illustration: a PDF invoice whose fields are extracted into a structured table