Back to all workflows
n8n21 nodes
AI Invoice Processing — With Claude AI
GmailClaude AIGoogle DriveNotionPDF ExtractStructured Output
The Problem
Processing invoice PDFs from email — opening attachments, reading line items, manually copying amounts into a database — eats hours every week. Errors creep in, line items get missed, and finance teams lose visibility into spend until month-end reconciliation.
The Solution
A 21-node n8n pipeline that watches Gmail for PDF attachments, uses a Claude AI controller to verify each is truly an invoice (and trash anything that isn't), then a second Claude chain extracts the structured data and writes each line item into a Notion database — fully hands-free with retry-safe storage on Google Drive.
How It Works
- 1📧 Gmail Trigger — polls inbox every minute for emails with PDF attachments
- 2✏️ Edit Fields — captures attachment keys + message ID for downstream nodes
- 3🔀 Split Out + Merge — splits multi-attachment emails, merges back with message context
- 4☁️ Upload file (Google Drive) — saves the PDF to an 'Invoices' folder for archival
- 5📥 Download file (Google Drive) — re-fetches the file as a binary stream
- 6📄 Extract from File — converts the PDF binary into raw text for AI processing
- 7🤖 Invoice Controller (Claude Haiku 4.5) — LLM agent that classifies: is this an invoice? (yes/no)
- 8📋 Structured Output Parser — enforces {status: yes/no} schema on the controller output
- 9🔀 IF Node — routes 'yes' → extraction chain; 'no' → delete the file
- 10🗑️ Delete a file (Google Drive) — cleans up non-invoice PDFs to keep storage tidy
- 11🧠 Basic LLM Chain (Claude Haiku 4.5) — extracts invoice_name, company_name, total amount, line items
- 12📋 Structured Output Parser — enforces strict JSON schema on the extracted invoice data
- 13📓 Create a database page (Notion) — creates the parent invoice record in Notion
- 14✏️ Edit Fields1 — preps line_items array + subject_id for batch processing
- 15🔀 Split Out1 — separates each line item into its own record
- 16🔁 Loop Over Items — iterates through line items one by one for safe batch inserts
- 17📓 Create a database page1 (Notion) — writes each line item to the 'Invoice Line Items' database
- 18✅ No Operation — clean loop exit when all items are processed
Results
- Every invoice PDF auto-archived, classified, extracted, and logged to Notion within seconds
- Two-stage Claude AI: first verifies it's an invoice, then extracts structured fields
- Non-invoice PDFs auto-deleted from Drive — zero storage bloat
- Each line item stored as its own Notion record — perfect for reporting & roll-ups
- Finance teams get real-time spend visibility without lifting a finger
Want something like this for your business?
I build custom AI-powered automations tailored to your workflows. Book a free 30-min call to discuss your use case.
Book a Free Call