Lovergil Perillo
All projects

n8n automation

AI Invoice Processing & Audit Agent - n8n Automation

An n8n automation that reads supplier invoices from email or Google Drive, pulls out the details with AI, and runs the checks a bookkeeper would run. Clean invoices go straight through. Anything suspicious goes to a reviewer with the reasons spelled out and one-click Approve / Reject buttons. Nothing disappears silently.

Tested with 19 sample invoices I generated, each with a known expected result. Every screenshot uses sample (demo) data.

The problem

Accounts payable teams get invoices as PDFs and photos, by email and through shared folders. Someone has to type each one in, then check it: does the math add up, is the vendor approved, does it match the purchase order, have we paid it already? It's slow, repetitive work, and the mistakes that slip through (duplicate payments, wrong totals, unknown vendors) cost real money.

What it saves

  • About 6 minutes of manual entry per invoice (estimate). Only problem invoices reach a person.
  • Catches costly mistakes before payment: wrong totals, duplicates, unknown vendors, purchase order mismatches and invoices over the approval limit.
  • Built to never lose an invoice: every AI, Gmail, Drive and database step retries 3 times; an unreadable file or an AI failure is flagged, not dropped; a sweep every 15 minutes picks up any file a trigger missed; and a separate crash-alert workflow emails me and logs the error if anything fails.

What it does

  • Picks up invoices from a Gmail label and from a Google Drive folder. One email with several attachments becomes several invoices, and tiny logos in email signatures are skipped.
  • Reads text PDFs directly and sends scanned PDFs and photos to the AI as images (OpenAI here; OpenRouter or any other LLM also works). The AI returns vendor, invoice number, dates, currency, PO number, line items, subtotal, tax, total and a confidence score for each field.
  • Cleans the data: dates in one format, amounts as numbers, trimmed vendor names, USD by default.
  • Runs the bookkeeper checks: required fields; line items vs subtotal; subtotal + tax vs total; due date before invoice date; duplicates; vendor on the approved list, with fuzzy matching so "ACME Corp." matches "Acme Corporation"; purchase order exists, belongs to the vendor and is within 2%; over the $5,000 approval limit; low AI confidence; and the AI's total and invoice number must actually appear in the PDF text.
  • Saves every invoice to Supabase, moves the file to "Processed" or "Needs Review", and labels the email.
  • Sends each flagged invoice to a reviewer by email with Approve / Reject buttons, and saves the decision and the time.
  • Sends a weekly report email every Monday at 8 AM (Manila time), with a short AI-written summary.

What I saw when I tested it

  • 19 sample invoices, 19 correct results: 8 clean (including a scanned photo and the "ACME Corp." spelling), 10 flagged with exactly the planted problem, and 1 email-signature logo skipped.
  • Invoice 09 was flagged "Subtotal + tax = $640.00, but the total says $690.00". Invoice 16 was flagged "Total $1,180.00 is 18.0% off PO amount $1,000.00".
  • An invoice sent by email went all the way through: copied to Drive, read, passed every check, moved to "Processed", and the email was labeled "Invoice-Processed".
  • Approve and Reject from the review email both saved the decision and the time. The crash alert and the weekly report email were both tested.

Built with

n8n (self-hosted)OpenAISupabaseGmailGoogle Drive

Screenshots

  • The Invoice Agent – Main workflow in n8n: Gmail, Google Drive and a 15-minute sweep feed file handling, AI extraction, bookkeeper checks, saving to Supabase, and routing to Processed or Needs Review.
    The main workflow: Gmail and Google Drive in, AI extraction, bookkeeper checks, save, then clean or flagged.
  • The Weekly Report workflow in n8n: every Monday it pulls this week's and last week's invoices and the time saved from Supabase, counts statuses and flag reasons, has the AI write a summary, and sends the email.
    Weekly Report workflow: pulls the numbers from Supabase, compares them with last week and emails the report.
  • Review email for Quantum Parts Ltd invoice QP-889 ($420.00): a red "Why it was flagged" box saying the vendor is not on the approved vendor list, the invoice details and line items, and Reject / Approve buttons.
    A flagged invoice goes to a reviewer with the reasons spelled out and one-click Approve / Reject.
  • Weekly invoice report email for Oct 26 to Nov 1, 2026: an AI-written summary, 18 processed, 44% clean rate, $27,978.00 total, 1.8 hours saved, a status table and the top flag reasons.
    Every Monday: invoices processed, clean rate, total amount, top flag reasons and hours saved, with a short AI summary.
  • Supabase invoices table from the test run with vendor, invoice number, total, status (clean, flagged, approved, rejected) and the flag reason for each invoice.
    Every invoice is saved with its status and the exact reason it was flagged.
  • Google Drive "Invoice Agent" folder with Email Attachments, Invoices Inbox, Needs Review, Processed and Test Invoices subfolders.
    Files are moved to Processed or Needs Review, so nothing disappears.
  • The Review Request workflow in n8n: flagged invoice received, make the invoice text safe, build the review email, ask the reviewer to approve or reject, save the decision.
    Review Request workflow: one run per flagged invoice, so every review waits on its own.
  • The Crash Alerts workflow in n8n: when an invoice workflow crashes, it formats the error details, saves them to the error_log table and emails the owner.
    Crash Alerts workflow: logs every failure to Supabase and emails me right away.
  • Crash alert email naming the failed workflow, the failed step, the error message and the time, with the run link blurred.
    If any workflow fails, an alert email shows which step failed and why.
Part of the same invoice systemInvoice Reporting Dashboard - WebsiteWrites the invoice data that the Invoice Reporting Dashboard shows and the Invoice Assistant Agent answers questions about.