Enterprise Invoice Automation & Security Suite
An n8n workflow that autonomously processes incoming invoices from Gmail — extracting data with AI, validating integrity through a…
Enterprise Invoice Automation & Security Suite

An n8n workflow that autonomously processes incoming invoices from Gmail — extracting data with AI, validating integrity through a triple-check audit system, detecting fraud, and requiring human approval before writing to the database.
Built as a production-ready, client-deployable system.
ARCHITECTUE A[Gmail Trigger\n Polls every 5 min] → B[Extract Email Metadata] B → C[LlamaParse\n Upload PDF] C → D[Wait 10s] D → E[LlamaParse\n Fetch Markdown] E → F[Openrouter\n Extract JSON Fields] F → G[Clean Output\n Parse JSON] G → H{Gate 1: Invoice QA\nInvoice number present?} H — No → I[Auto-Reply to Sender\nRequest resubmission] H — Yes → J[Math Engine\nVerify totals and VAT] J → K{Gate 2: Accuracy Check\nCalculations valid?} K — No → L[Email Alert\nFlag to Finance Team] K — Yes → M[Supabase\nLook up vendor] M → N{New vendor?} N — Yes → O[Register vendor\nin Supabase] O → P[Supabase\nCheck for duplicate invoice] N — No → P P → Q{Gate 3: Fraud Check\nDuplicate found?} Q — Yes → R[Slack Alert\nFRAUD/DUPLICATE WARNING] Q — No → S[Slack HITL\nRequest human approval] S → T[Insert to\nInvoice Database] T → U[Update status\nAPPROVED] U → V[Archive in Gmail\nRemove from INBOX]
Features
Triple-Check Audit System
Gate 1 — Quality Check Inspects the extracted JSON for a valid invoice_number. If missing or null, the workflow automatically replies to the sender with a formatted HTML email requesting a clean resubmission — no human involvement needed.
Gate 2 — Math Engine Custom JavaScript re-calculates:
- Expected total:
subtotal + tax - Expected VAT:
subtotal × 0.20(configurable rate)
Flags mismatches within a £0.05 tolerance and sends an alert to the finance team email. The invoice is paused until corrected.
Gate 3 — Fraud & Duplicate Detection Cross-references the extracted invoice_number and vendor against the Supabase master ledger. Fires an immediate Slack alert on any duplicate — acting as a 24/7 financial sentry.
Human-in-the-Loop (HITL)
Uses n8n’s sendAndWait Slack node. The workflow pauses and will not write to the database until a designated approver clicks Approve in Slack. No invoice is committed without a human decision.
Vendor Registry
Automatically registers new vendors in a Supabase vendors table on first invoice receipt. Subsequent invoices from the same vendor skip registration and go straight to duplicate checking.
Gmail Lifecycle Management
Each invoice exits with the correct Gmail label regardless of outcome:
- Failed QA → labelled and archived
- Math error → labelled and archived
- Fraud detected → labelled and archived
- Approved → labelled and archived
Your inbox stays clean automatically.
Error Resilience
Every node has retryOnFail: true. A separate error-monitoring workflow (errorWorkflow) catches any execution failure and notifies the developer with a direct execution link — no silent failures.
Tech Stack
LayerToolWorkflow orchestrationn8nPDF parsingLlamaIndex LlamaParse APIAI extractionGoogle Gemini (via n8n LangChain nodes)DatabaseSupabase (PostgreSQL)Notifications & HITLSlackEmail trigger & managementGmail APIMath validationn8n Code node (JavaScript)
Prerequisites
- n8n instance (cloud or self-hosted)
- LlamaIndex Cloud account (LlamaParse API key)
- Google Gemini API key
- Supabase project
- Slack workspace with a dedicated channel
- Gmail account connected via OAuth2
Supabase Schema
Create two tables in your Supabase project before importing the workflow.
vendors table
create table vendors (
id uuid default gen_random_uuid() primary key,
name text not null,
created_at timestamptz default now()
);
invoices table
create table invoices (
id uuid default gen_random_uuid() primary key,
invoice_number text,
total_amount numeric,
currency text,
vendor_name text,
tax_amount numeric,
raw_ai_output jsonb,
status text default 'PENDING',
created_at timestamptz default now()
);
Setup
- Import the workflow
- In n8n, go to Workflows → Import from file
- Select
workflow/invoice_automation.json
- Configure credentials
Gmail OAuth2— connect your Gmail accountGoogle Gemini (PaLM) API— add your Gemini API keySupabase API— add your project URL and service role keyLlamaParse Header Auth— addAuthorization: Bearer YOUR_LLAMAPARSE_KEYSlack API— add your Slack bot token
- Update workflow variables
- Slack channel ID → your approval channel
- Finance team email → your error alert recipient
- Gmail label ID → create a label in Gmail and paste its ID (found via Gmail API or Settings)
- Deploy error workflow
- Create a separate n8n workflow to handle errors
- Set its ID in the workflow settings under
errorWorkflow
- Activate the workflow
Customization
ParameterDefaultHow to changePolling intervalEvery 5 minutesGmail Trigger node → pollTimesVAT rate20%Calculator node → net * 0.20Email filtersubject contains "invoice" or "bill"Gmail Trigger → filters.qDatabaseSupabaseReplace Supabase nodes with your preferred DBApproval channelSingle Slack channelRoute vendors to different channels via IF nodes
Project Status
Production-ready. Built and tested with live invoice data. Execution logs confirm successful end-to-end runs across all branches including fraud detection and HITL approval paths.

메타데이터
- post_id
- fd2e3a52b972
- slug
- enterprise-invoice-automation-security-suite-fd2e3a52b972
- url
- https://medium.com/@somuma1074/enterprise-invoice-automation-security-suite-fd2e3a52b972
- canonical_url
- https://medium.com/@somuma1074/enterprise-invoice-automation-security-suite-fd2e3a52b972
- author_url
- https://medium.com/@somuma1074
- status
- ok
- fetched_at
- 2026-08-28 17:57:26