DEV Community

Ahmed Negm
Ahmed Negm

Posted on AI-assisted

A safer n8n invoice workflow: extract, validate, then review

An invoice workflow can fail in two different ways: it can extract the wrong value, or it can confidently move a correct-looking value into the wrong business action. I designed this n8n demo to make those steps visible and keep approval outside the automation.

The example processes Arabic or English invoices supplied as PDF, JPG, or PNG. It uses Gemini to extract fields, then applies deterministic checks to catch arithmetic inconsistencies before writing a record to an n8n Data Table. Each record remains pending review.

The flow

  1. Receive the file. The workflow accepts an invoice document and routes supported formats into extraction.
  2. Extract candidate fields. Gemini returns structured values such as supplier, invoice number, line amounts, tax, and total. These are suggestions from a model, not trusted accounting data.
  3. Check arithmetic in code. The workflow recalculates totals and compares them with the extracted total. A mismatch is recorded as a validation issue rather than silently accepted.
  4. Look for duplicates. It checks the supplier and invoice number against prior records. This catches a common repeat-submission case, though it is not a universal duplicate detector.
  5. Save for review. The result is written to an n8n Data Table with a pending-review state so a person can inspect the document and extracted values.

Why keep approval separate?

Extraction quality and business authorization are different questions. A model can help turn an unstructured document into fields, and code can check arithmetic, but neither decides whether a payment should be approved. Keeping the demo at “pending review” makes that boundary explicit.

The same separation is useful when tailoring an invoice process for a business: define what the system may extract, which checks can be deterministic, who reviews exceptions, and what authenticated downstream action is permitted. A production integration would also need the customer’s document storage, access rules, accounting system, retention policy, and error-handling requirements. Those are not included here.

What I verified

The repository includes two workflow exports, six screenshots, synthetic invoice examples, and 26 passing offline checks. Those checks do not establish a fresh live n8n run or production readiness. The public exports need credentials, the supporting subworkflow and Data Tables to be configured, and fresh runtime testing; the backup Gemini model also needs review. The demo does not approve invoices, post to an ERP, or claim zero errors or measured savings.

Source and setup notes: https://github.com/ahmednegm91/intelligent-invoice-processing

This is a portfolio demonstration of an approach I can adapt after requirements and approval boundaries are clear.

Top comments (0)