Tutorial 8 min read

Automating Invoice Processing: From PDF to Payment

Author
February 2, 2025

Every month, finance teams waste hundreds of hours manually keying invoice data into accounting software. Today, we will build a pipeline that does this automatically using OpenAI Vision and n8n.

The Tech Stack

  • Trigger: Gmail (emails with attachment "Invoice")
  • Processing: OpenAI GPT-4o (Vision)
  • Destination: Xero / QuickBooks / Google Sheets

Step 1: The Prompt

The key to accurate extraction is a robust system prompt. When sending the image to OpenAI, use structured JSON instructions:

Extract the following fields from the invoice image:
- invoice_number (string)
- date (ISO 8601)
- total_amount (number)
- currency (string)
- vendor_name (string)
- line_items (array of objects)

Return ONLY raw JSON.

Step 2: Handling the Logic

In n8n, we set up a "Switch" node.

If confidence > 90%: Create Bill in Xero as "Draft".
If confidence < 90%: Send to Slack channel #finance-review for manual check.

Sound too technical?

Get the Pre-Built Workflow

Why not just use traditional OCR?

Legacy OCR templates break when a vendor changes their layout. LLMs like GPT-4o understand the *context* of a document, so they work across thousands of different invoice formats without specific training.

Streamline your finance ops.

We build secure financial automation pipelines.

Automate Finance
Back to Insights