A workflow that reads incoming PDF invoices, matches them against purchase orders in the ERP, and books matches automatically while routing discrepancies to the finance team for manual review.
automatingreviewingdata-driven
Description
Incoming invoices are a quiet time sink in many small and mid sized companies: PDFs sitting in an inbox, line items typed in by hand, matching against the purchase order by eye, and weeks passing before anything gets booked. The Invoice Pipeline takes this process off your hands. It reads every incoming invoice, matches it in a structured way against purchase order data and goods receipt in the ERP, and triggers the booking in the accounting system on a match.
What gets automated is the extraction of invoice data into a clean JSON format, and the matching against supplier, amount, description of goods or services, and purchase order number within a defined tolerance. What deliberately stays out of automation is the decision on discrepancies: if something falls outside the tolerance window, the case goes to the finance team with full details instead of being booked through automatically. Every step, from extraction to the booking decision, is also recorded in an audit log, so the pipeline stays traceable instead of becoming a black box.
The result is not a fully autonomous accounting agent but a pre sorting layer with a clear boundary: routine invoices go straight through, anything unusual lands with a person. This noticeably shortens the turnaround time and, as a side effect, creates room to actually make use of early payment discount deadlines.
Faster turnaround: Invoices are processed in minutes instead of sitting in the inbox for days.
Fewer errors: Automatic matching between invoice, purchase order, and goods receipt reduces typing mistakes and things that get overlooked.
Finance relieved: Routine invoices are booked automatically, only discrepancies go to the finance team for review.
Discounts captured: The short turnaround time creates room to actually meet early payment discount deadlines.
Steps
Every step shows who carries it out: icon, colour and label together indicate whether a person acts, whether it runs automatically, whether a result is produced, or whether an approval is required.
01 · Person
The process starts as soon as a new email with a PDF invoice arrives in the invoice inbox.
02 · Automated
A language model reads the invoice and returns invoice number, supplier, amounts, due date, IBAN, and purchase order number as structured JSON.
03 · Automated
The extracted data is checked against the purchase order data in the ERP: supplier, amount within the defined tolerance, description of goods or services, and purchase order number.
04 · Automated
The process evaluates whether all criteria fall within the tolerance range and derives the further route from that.
05 · Result
On a match, the invoice is booked in the accounting system with the matching cost center and account.
06 · Person
On a discrepancy, a ticket or message with full details goes to the finance team for manual review.
07 · Result
The incoming email, the extracted JSON, the match result, and the final status are logged.
Key
PersonAutomatedResultApproval
Requirements and operations
Requirements
Invoice inboxA dedicated address for incoming PDFs, for example [email protected].
ERP or purchase order systemSAP, Dynamics, or Odoo supplies the purchase order data and goods receipts.
Accounting systemDATEV, Lexoffice, or a comparable system books the approved invoices.
LLM access and team chatAccess to OpenAI, Claude, or Gemini for extraction and matching, plus Slack or Teams for escalations.
Testing
Test invoicesTest a real invoice with a matching purchase order and a second one with a deviating amount.
ExtractionCheck whether invoice number, supplier, amounts, IBAN, and purchase order number are correct in the JSON.
Matching and bookingCheck whether the tolerance applies correctly and the right invoice actually gets booked.
Edge casesTest poor scans, missing purchase order numbers, foreign currency, and duplicate submissions.
Go-live
ApprovalActivate the workflow only once extraction, matching, and booking are reliably correct.
PilotStart with a single top supplier and roll out step by step from there.
Mapping and toleranceFine tune the account or cost center mapping and the tolerance value iteratively.
ExpandAdd duplicate detection, a tiered approval workflow above a threshold, and reporting as a next step.
Common issues
Poor OCR qualityUse a stronger model or enforce a higher minimum scan resolution.
Tolerance value too narrow or too wideCalibrate the value against real invoices from the past.
Missing purchase order numberUse fallback matching by supplier, amount, and date.
Duplicate bookingCheck invoice number and supplier together as a unique key.
Builder Prompt
Copy the prompt below in full into your automation tool or agent builder. As a file: rechnungs-strecke.en.json
GOAL
Build a workflow that automatically extracts invoice data from incoming PDF invoices, matches it against purchase order data and goods receipt in the ERP, and triggers the booking in the accounting system on a match. On discrepancies, the workflow notifies the finance team with full details and flags the case for manual review instead of booking it through automatically.
Adapt the structure to the concepts of your automation tool (for example nodes, steps, zaps, or agent actions). While doing so, preserve the trigger logic, the sequence, the branching, and the data flow.
TRIGGER
Type: new email with a PDF attachment in the dedicated invoice inbox, for example [email protected].
Filter: only attachments of type PDF, other emails are ignored.
STEPS
1. Read the PDF: obtain the text via OCR or extraction from the attachment.
2. AI step: data extraction. Use exactly the Invoice Data Extraction working prompt (see the Working Prompts section). Output: JSON with all invoice fields.
3. Duplicate check: check invoice number and supplier together as a unique key against already processed invoices. On a duplicate, jump directly to step 7 and flag the case as a duplicate.
4. Load purchase order data: load the purchase order data via the purchase order number from the ERP (SAP, Dynamics, or Odoo). If the purchase order number is missing, use matching by supplier, amount, and date as a fallback.
5. AI step: matching. Use exactly the Discrepancy Analysis working prompt (see the Working Prompts section) with the invoice JSON and the purchase order JSON as input. Output: JSON with a recommendation.
6. Branch: if the recommendation is book_automatically, trigger the booking in the accounting system (DATEV, Lexoffice, or comparable) with cost center and account mapping.
7. Otherwise, or on a duplicate or a missing purchase order: escalate to the finance team via ticket or a message in Slack or Teams, with invoice data, purchase order data, and all discrepancy details. Flag the case for manual review.
8. Both branches: log the incoming email, the extracted JSON, the match result, and the final status in the audit log.
PROMPTS
Take over both working prompts from the section of the same name unchanged and in full. Do not alter the placeholders they contain, and map them as described in the data flow.
DATA FLOW
Step 1 to step 2: extracted invoice text.
Step 2 to steps 3, 4, and 5: invoice JSON.
Step 4 to step 5: purchase order data as purchase order JSON.
Step 5 to steps 6 and 7: the recommendation, discrepancies found, details, and rationale fields from the match result.
ERROR HANDLING
Incomplete extraction, for example a missing invoice number or gross amount: do not book, escalate instead, and state the cause in the review note.
No purchase order found, even with fallback matching: do not book, escalate instead.
Duplicate detected: do not book, escalate as a duplicate instead.
Foreign currency or an unusual format: escalate for manual review.
Principle: when in doubt, never book automatically, escalate instead.
PLACEHOLDER CONVENTION
All placeholders in square brackets inside the two working prompts are mapped dynamically, as described in the data flow. The tolerance percentage in the matching prompt is not dynamic: you set it yourself before activation, calibrated against real invoices from the past. List all placeholders that require manual configuration separately at the end.
SELF CHECK BEFORE COMPLETION
Check, before you report the workflow as finished:
1. Are all steps connected correctly, in particular the branch between booking and escalation and the audit log in both branches?
2. Are both working prompts inserted in full and unchanged, and is the tolerance percentage mapped?
3. Do the duplicate check and the fallback matching work as described?
4. Are all points listed that require manual configuration: invoice inbox, ERP and accounting system access, cost center and account mapping, tolerance percentage, and escalation channel?
Working prompts
Invoice Data Extraction
Reads the incoming invoice and returns all relevant fields as structured JSON.
You are an expert in invoice analysis. Analyze the following invoice and extract all relevant data into a structured JSON format. If a detail is not unambiguously stated in the invoice text, mark it as an assumption rather than presenting it as certain.
INVOICE:
[INVOICE_TEXT]
Extract the following information:
- Invoice number
- Supplier/issuer (name and address)
- Invoice date
- Due date
- Net amount
- VAT rate and amount
- Gross amount (total)
- Description of goods or services/line items
- Purchase order number (if available)
- IBAN/bank details
OUTPUT FORMAT (JSON):
{
"invoice_number": "...",
"supplier": {"name": "...", "address": "..."},
"invoice_date": "YYYY-MM-DD",
"due_date": "YYYY-MM-DD",
"net_amount": 0.00,
"vat_rate": 0.00,
"vat_amount": 0.00,
"gross_amount": 0.00,
"line_items": ["Item 1", "Item 2"],
"purchase_order_number": "...",
"iban": "..."
}
If information is not available, set the value to null. Use correct number formats with a period as the decimal separator.
Discrepancy Analysis
Compares the extracted invoice data with the purchase order data and returns a structured recommendation.
You are an expert in invoice auditing. Compare the extracted invoice data with the purchase order data and identify discrepancies. Explicitly mark any assessment for which relevant information is missing as an assumption.
INVOICE DATA:
[INVOICE_DATA_JSON]
PURCHASE ORDER DATA:
[PURCHASE_ORDER_DATA_JSON]
CHECK CRITERIA:
- Supplier matches
- Amount deviates by no more than [TOLERANCE_PERCENT]%
- Description of goods or services matches the purchase order
- Purchase order number is correct (if available)
OUTPUT:
Create a structured analysis in the following JSON format:
{
"discrepancies_found": true/false,
"details": [
{"category": "Amount/Supplier/Service", "description": "...", "severity": "critical/medium/low"}
],
"recommendation": "book_automatically" or "manual_review_required",
"rationale": "..."
}
Be precise and state concrete figures for discrepancies. Amounts with a deviation below [TOLERANCE_PERCENT]% are considered correct.
JSON export
Setup
Two routes lead to the same result. Pick the one that fits your setup.
Suitable when you want to build the workflow in your own automation tool.
Open your workflow tool, for example n8n, Make, Zapier or Langdock.
Create a new workflow and give it a name.
Choose the AI-assisted build option if your tool offers one.
Paste the builder prompt from above in full.
Check the result against the step sequence in this document, then add your access credentials and channels.
Suitable when you want to take the workflow over unchanged.
Download the JSON file from the JSON export section.
Open the workflow area of your tool and create a new workflow.
Give it a name and confirm.
Open the menu on the workflow name and choose to import a JSON file.
Upload the file, then add your own access credentials.
Run a test before you activate the workflow.
Last reviewed:
In the workshop this becomes your method.
A single prompt becomes a repeatable method. We show that in the workshop From Prompt to Method.