Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

n8n: Turn Invoice PDFs Into JSON With AI, Then Two-Way Match Them Against the PO in a Code Node

Description and use

A complete n8n workflow converts invoice PDFs to structured JSON using AI extraction, then two-way matches them against PO lines stored in a Google Sheet. Mismatches are flagged with specific reasons so the user only reviews problematic invoices rather than every invoice.

Problem

Paying vendor invoices requires manual typing of vendor, invoice number and total into a spreadsheet, then a separate manual check that the invoice matches the purchase order. The matching check is frequently skipped on busy weeks, allowing price creep, unordered line items, or invoices with no PO.

Outcome

A complete n8n workflow converts invoice PDFs to structured JSON using AI extraction, then two-way matches them against PO lines stored in a Google Sheet. Mismatches are flagged with specific reasons so the user only reviews problematic invoices rather than every invoice.

Workflow

  • Gmail Trigger catches invoice emails; turn Simplify off and add Download Attachments to get the first attachment as binary data called attachment_0
  • Extract from File, operation Extract From PDF, turns the PDF into plain text
  • Information Extractor with OpenAI Chat Model pulls fields out of the text into a fixed shape using Generate From JSON Example schema with fields: vendor, invoice_number, po_number, invoice_date, due_date, total, and line_items (item, qty, unit_price)
  • Google Sheets Get row(s) in sheet reads PO rows with columns po_number, vendor, item, qty, unit_price; filter on po_number equal to $json.output.po_number
  • Code node Run Once for All Items performs the two-way match comparing invoice totals and line items against PO lines within tolerances: TOTAL_TOLERANCE = 5.00 dollars, PRICE_TOLERANCE = 0.01 per unit
  • Non-matching invoices are flagged with reasons such as missing PO number, PO not found, total mismatch, price mismatch, or line item mismatch

Evidence

In most small offices, paying a vendor invoice goes like this. The PDF arrives by email. Someone types the vendor, invoice number and total into a spreadsheet. Then, if they're careful, they pull up the purchase order and check that the invoice matches what was ordered.

Source

That last check is the one that gets skipped on a busy week. It's also the one that catches a price that crept up, a line nobody ordered, or an invoice with no PO behind it at all.

Source

Two-way matching fits services and low-risk purchases: software, consulting, cleaning, a monthly retainer. For physical goods, many businesses add the receiving record and run a three-way match, because a two-way match can't tell you whether 40 cartons actually arrived.

Source

One honest limit: Extract from File needs a PDF with real text in it. A scanned invoice that is only an image has no text to extract, so you'd add an OCR step before the extractor.

Source

The instructions in Text matter more than the model. The lesson's rule is the

  • Record date: 2026-10-21T18:26:06.259Z