Skip to content
Is there an AI for this?

Self-hosted

Invoice capture and extraction

Invoices arrive by email or watched folder, Docling converts them (OCR included), a local vision-capable model fills a JSON schema under constrained decoding, code checks the arithmetic and the supplier against your master data, and n8n posts the clean ones while routing the rest to a person.

Source
Editorial recipe — no step evidence has been fetched yet
Verified
Evidence not verified
Confidence
Low

01Objective

Turn incoming supplier invoices — PDF, scan or email attachment — into validated structured records in the accounting system, with a human queue for anything uncertain.


02Recommended stack

6 components
RoleComponent
InferenceMistral-Small-3.2-24B-Instruct or Gemma-3-12B-IT (vision-capable)
InferencevLLM with structured outputs
IngestionDocling
IngestionoptionalPaperless-ngx
Orchestrationn8n
StoragePostgreSQL

Architecture and data flow

Architecture for Invoice capture and extraction10 components in 6 layers. Trust boundaries: COMPANY NETWORK; PRIVATE CLOUD · Your cloud tenancy. External data transfer: SOME. Some data leaves the boundary drawn here.Finance team (exception queue)Mailbox / consume folder → Docling (OCR)n8n workflow + review screenExtraction + validation servicePostgreSQL (extractions, audit trail)Invoice archive (originals)vLLM (structured outputs)Mistral-Small-3.2-24B-InstructCompany GPU server (24 GB)Finance team (exception queue)Finance team (exception…PEOPLEMailbox / consume folder → Docling (OCR)Mailbox / consume folde…STORAGEn8n workflow + review screenn8n workflow + review s…APPLICATIONExtraction + validation serviceExtraction + validation…RETRIEVALAccounting systemEXTERNAL APIPostgreSQL (extractions, audit trail)PostgreSQL (extractions…DATABASEInvoice archive (originals)Invoice archive (origin…STORAGEvLLM (structured outputs)vLLM (structured output…INFERENCE SERVERMistral-Small-3.2-24B-InstructMistral-Small-3.2-24B-I…MODELCompany GPU server (24 GB)Company GPU server (24 …HARDWARECOMPANY NETWORKPRIVATE CLOUD · Your cloud tenancyHTTPSCONFIDENTIALdocuments to indexCONFIDENTIALquestion + user groupsCONFIDENTIALdocuments + permissionsCONFIDENTIALchats, users, settingsPERSONALoriginal filesCONFIDENTIALprompt + retrieved passagesCONFIDENTIALloaded weightsGPU memoryGPU memoryvalidated invoice postingsCONFIDENTIALEXTERNAL DATA TRANSFER · SOME

Components

  • Finance team (exception queue) — people
  • Mailbox / consume folder → Docling (OCR) — storage
  • n8n workflow + review screen — application
  • Extraction + validation service — retrieval
  • Accounting system — external api
  • PostgreSQL (extractions, audit trail) — database
  • Invoice archive (originals) — storage
  • vLLM (structured outputs) — inference server
  • Mistral-Small-3.2-24B-Instruct — model
  • Company GPU server (24 GB) — hardware

Connections

  • Finance team (exception queue) to n8n workflow + review screen — HTTPS (confidential data)
  • Mailbox / consume folder → Docling (OCR) to Extraction + validation service — documents to index (confidential data)
  • n8n workflow + review screen to Extraction + validation service — question + user groups (confidential data)
  • Extraction + validation service to PostgreSQL (extractions, audit trail) — documents + permissions (confidential data)
  • n8n workflow + review screen to PostgreSQL (extractions, audit trail) — chats, users, settings (personal data)
  • Extraction + validation service to Invoice archive (originals) — original files (confidential data)
  • Extraction + validation service to vLLM (structured outputs) — prompt + retrieved passages (confidential data)
  • vLLM (structured outputs) to Mistral-Small-3.2-24B-Instruct — loaded weights
  • Mistral-Small-3.2-24B-Instruct to Company GPU server (24 GB) — GPU memory
  • vLLM (structured outputs) to Company GPU server (24 GB) — GPU memory
  • n8n workflow + review screen to Accounting system — validated invoice postings (confidential data)

External data transfer · SOME

  • confidential content leaves your premises for your own cloud tenancy ("Accounting system"). You keep control of the account; the provider is a processor, so a DPA and a documented region apply.
  • Invoices are read and extracted entirely on your own machines; the only outbound flow is the posting into your own accounting system.
  • If the accounting system is itself a SaaS product, that link inherits its terms — worth stating explicitly when the design is reviewed.

03Suitable for

Organisation size
10–1000 employees
Data classes
confidential, personal
Constraints
enough invoice volume for automation to pay back — typically 200+ per month; an accounting system with an API or a supported import format; someone in finance who owns the exception queue; a 24 GB GPU; a CPU-only pilot is possible at low volume
Industries
Accounting, Professional services, Manufacturing, Logistics, Retail
Jurisdictions
any

04Hardware

  • On-premise single 24 GB GPU server

    GPU
    NVIDIA RTX 4090 24 GB (or NVIDIA L4 24 GB for a rack-mounted, 72 W alternative)
    VRAM
    24 GB
    System RAM
    64 GB
    Storage
    2000 GB
    CPU
    16-core x86 server CPU (AMD EPYC 7003/9004 or Intel Xeon Scalable)
    Form factor
    Tower server

    Indicative costUS$4,000 – US$9,000

    indicative build cost for the complete machine, USD, Aug 2026 — verify with a local supplier

    The default box for a 20–60 person firm. Fits a 14B model at 4-bit with roughly 8 GB of KV cache left for concurrent chat, or an 8B model at fp16. NVMe storage sized for the model cache plus a document corpus and its embeddings. Add a UPS and an offsite backup target — this machine holds the whole knowledge base.

  • CPU-only server (small models and embeddings)

    GPU
    unknown
    VRAM
    unknown
    System RAM
    64 GB
    Storage
    1000 GB
    CPU
    16–32 core x86 server CPU with AVX-512
    Form factor
    Tower server

    Indicative costUS$1,500 – US$4,000

    indicative build cost for the complete machine, USD, Aug 2026 — verify with a local supplier

    No GPU. Embedding models and document parsing run acceptably here, which is enough for a search-only pilot or a nightly batch pipeline. Chat generation with a 7–8B model at 4-bit works but reads at a few tokens per second — usable for one person testing, not for a team. The honest use of this profile is to prove the retrieval quality before buying a GPU.

Indicative costUSD · one-off plus monthly

Software licences
All components are open source and self-installed. Check each licence for use limits.
US$0
Model usage
Open weights served locally: no per-token charge. The GPU cost sits under infrastructure.
US$0
GPU server (24 GB class), purchased
Hardware profile onprem-small-24gb — indicative build cost, Aug 2026, verify locally.
US$4,000 – US$9,000
Implementation (8–20 FDE-days)
8–20 FDE-days at US$760–1940 per day, converted from the HK$6,000–15,000 band at the HKMA Linked Exchange Rate band of HK$7.75–7.85 to one US dollar. One-off; excludes internal staff time.
US$6,080 – US$38,800
  • 200–5,000 invoices per month, one accounting system, one exception queue.
  • The implementation band widens sharply if the accounting system has no usable API.
  • Excludes the finance time spent on exceptions, which dominates the running cost until the straight-through rate is high.
  • Every figure is an assessment from the inputs listed, not a quotation.

05Difficulty

4 / 5

Multiple weeks and a team that has shipped infrastructure


06Skills

API integrationapi-integration
development
Data engineeringdata-engineering
data
Dockerdocker
infrastructure
Linuxlinux
operations
LLM evaluationllm-evaluation
ml
LLM inferencellm-inference
ml
OCR and document parsingocr
ml
PostgreSQLpostgresql
data
Pythonpython
development
Workflow automationworkflow-automation
operations

07Deployment steps

7 steps

Commands are copied from each project’s own documentation, and the page they came from is linked under the step. 0 of 7 steps currently open an evidence record. The rest are linked to their source; §10 says which of those documents were fetched and which were fetched without their anchor being found — two different states, named differently there.

  1. 01

    Collect 200 real invoices before writing anything

    Assessment

    Take a genuine month, including the ugly ones: photographed, multi-page, foreign currency, credit notes, handwritten annotations. Bucket them by supplier. Ten suppliers usually make up most of the volume — automating those ten well beats automating everything badly.

  2. 02

    Convert and OCR with Doclingversion-sensitive

    Assessment

    Install Docling and convert the sample. Check line-item tables specifically: if the table structure survives conversion, extraction is straightforward; if it does not, no amount of prompting will recover it.

    pip install docling
    docling https://arxiv.org/pdf/2206.01062

    from the Docling README

    Source documentation

  3. 03

    Write the invoice schema and extract against itversion-sensitive

    Assessment

    Fields: supplier name and tax id, invoice number, dates, currency, line items, net, tax, gross, purchase-order reference. vLLM "supports the generation of structured outputs using xgrammar or guidance as backends" — use the schema so every result parses. Require a confidence and a source quote per field.

    Source documentation

  4. 04

    Validate in code, never in the model

    Assessment

    Line items must sum to net; net plus tax must equal gross; the tax rate must be one your jurisdiction allows; the supplier must match your master data; the invoice number must not already exist. Arithmetic belongs in code — a language model is the wrong tool for a sum, and a failed check is the cheapest possible error detector.

  5. 05

    Wire the workflow in n8nversion-sensitive

    Assessment

    Trigger on the mailbox or consume folder, call conversion and extraction, run validation, branch: clean invoices post to the accounting system, anything that fails a check or falls below the confidence threshold goes to the exception queue with the reason attached. Add retries and an alert when the queue stops draining.

    docker volume create n8n_data
    
    docker run -it --rm \
     --name n8n \
     -p 5678:5678 \
     -e GENERIC_TIMEZONE="<YOUR_TIMEZONE>" \
     -e TZ="<YOUR_TIMEZONE>" \
     -e N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true \
     -e N8N_RUNNERS_ENABLED=true \
     -v n8n_data:/home/node/.n8n \
     docker.n8n.io/n8nio/n8n

    from the n8n docs — set your timezone

    Source documentation

  6. 06

    Keep the original next to the extraction

    Assessment

    Store the source file and the extraction together, with the model and prompt version. Paperless-ngx does this well if you also need the invoices searchable; a folder plus a database row is enough if you do not. Either way, an extraction you cannot trace back to an image is not auditable.

    Source documentation

  7. 07

    Run in shadow mode and measure the exception rate

    Assessment

    For the first month, extract everything but post nothing: compare against what finance keyed manually. Report straight-through rate and the reasons for exceptions by supplier. Go live per supplier as each one clears the bar, not all at once.


08Compliance considerations

Structured issue-spotting to support your own review — not legal advice. Verify against the cited primary sources and your counsel.

Applies everywhere

  • Personal data · Retentionmedium

    Invoices carry personal data (contacts, bank details, sometimes employee names) and are usually subject to a statutory accounting retention period. That period governs the archive; it does not automatically justify keeping every intermediate extraction.

  • Sector rules · Auditabilityhigh

    Tax and audit rules in most jurisdictions require the original document to remain available and unaltered. Keep the source file, not just the extracted values, and record who approved each posting.

  • Human oversight · Automated decision-makinghigh

    Automatic posting is an automated decision with a financial effect. Set a value threshold above which a person always approves, and make the exception queue someone's named job.

  • Security · Confidentialityhigh

    Supplier bank details are a fraud target. The mailbox, the pipeline and the accounting credentials all need to be treated as payment infrastructure, including change control on bank-detail updates.


09Alternatives

  • A specialist capture vendor

    Purpose-built invoice capture arrives pre-trained on millions of invoices and ships the exception UI. Usually more accurate on day one than anything you build in a fortnight.

    • Accurate immediately, no model to run
    • Invoices go to a processor: DPA, residency and retention questions
    • Per-document pricing that scales with volume

    rossumnanonets

  • Your accounting system's own capture feature

    Most accounting platforms now include capture. If it covers your top ten suppliers, the integration work disappears entirely.

    • Nothing to integrate
    • Little control over accuracy or exception handling
    • Data goes wherever the accounting vendor processes it

No alternative recipe is published yet.


10Evidence

0 of 6 fetched

11Community

Deployed this stack, or hit something this page does not cover? Corrections, sources and implementation reports are what keep a recipe worth reading.

Improve this page

Sign in to contribute

From the field

0 deployments · 0 questions

Nobody has reported deploying this here yet, and no question has been opened against this page. Both appear once a reviewer accepts them.


12Hire an FDE

If you would rather not build it, we can introduce a forward-deployed engineer who has deployed this stack before. The enquiry form starts from this recipe.