Skip to learning content
← All use cases
RAG free

Resolving invoice exceptions across PDFs and ERP

Follow a EUR 400 invoice difference from the supplier PDF to a clear review report. Build the record checks, add policy search where it helps, and test the workflow before connecting real ERP actions.

The question: Why does this invoice disagree with the order and delivery records, and who should resolve it?

You’ll learn: Build a checked invoice record and an evidence-linked review report; choose the document reader, exact checks and optional policy search.

For: Finance teams, product owners and engineers. No AI background needed.

Executed teaching prototype · AI-assisted source check . This is not a human expert endorsement.

Chapter 3: Review, test and roll out

3. Review, test and roll out#

Step 8. Show a report people can use#

On the review screenExample
What is wrong?The invoice bills 20 more units than the order and receipt support.
How much needs checking?EUR 400, excluding tax.
What can I open?Invoice page 1; order line 1; receipt line 1; the applicable policy clause.
Who acts next?Purchasing checks for an approved amendment; receiving checks for a missing receipt.
What happens after that?Finance checks the new evidence or requests a corrected invoice.
Has anything been paid?No. This report is a review record.

Put the invoice page beside the checked fields. Highlight the source region only when extraction actually supplied it. Let reviewers correct a field with a reason; keep the old value and file version in the history. Record who resolved the exception and what evidence changed.

If you later add an ERP write, show the exact proposed change first. Recheck permission and source versions when the reviewer approves. A changed order invalidates the old proposal. Use a separate write adapter and a unique action key so a retry cannot submit the same change twice.

Put controls at each hand-off#

PlaceControl to implement
UploadAllow expected file types; check content, size and page limits; scan files; parse in an isolated worker with no ERP credentials.
Files and recordsUse company-scoped storage and expiring source links. Recheck access when someone opens an attachment.
Models and searchTreat PDF and policy text as untrusted data. They cannot grant permissions, change tools or approve payments.
ERP adapterUse narrow read permissions. Keep credentials on the server and restrict which hosts it can call.
Logs and retentionLog IDs and failure codes by default. Set retention with finance; remove expired copies, search chunks and vectors together.
Provider callsConfirm the approved processing location, retention and data agreement before sending real invoices.

Source: File-upload controls ↗

Source: Why document text must not control tools or permissions ↗

Go deeper · optional · freeWhat happens when a PDF tells the AI to ignore the rules? ↗Prompt injection and trust boundaries

Step 9. Test the failures before expanding#

Test invoice or questionExpected behavior
120 billed; 100 ordered and receivedHold the EUR 400 quantity difference.
Missing or stale receiptHold; delivery support is unknown.
Some quantity already billedSubtract it before checking the current invoice.
Different supplier, currency or unitStop; do not compare incompatible records.
Duplicate invoiceFlag the duplicate; do not create another payment proposal.
Discounted price and excess quantityShow both checks; do not let one cancel the other.
Old or wrong-company policy ranks firstDo not show it; use an authorized applicable passage or abstain.
Instruction hidden in the PDFTreat it as document content; permissions remain unchanged.
Worker restarts or ERP times outResume or fail clearly without a repeated action.

Measure missed exceptions, false alarms, wrong field values, useful policy passages and reviewer correction time. Include provider calls, retries and human review in the cost. Compare with the current process on the same invoices. Set the acceptance limits with finance before reading the results.

Go deeper · optional · freeBuild a test set that catches real failures ↗Evaluating enterprise AI against business outcomes

Run the downloadable example#

Download the invoice exception lab. Unzip it, open a terminal in the extracted folder, and use Python 3.11 or later. The checker needs only Python’s standard library.

shell
python invoice_lab.py --input fixtures/base.json
python -m unittest discover -s tests -v

Open the synthetic PDF, compare it with fixtures/base.json, and run the command. Read the reason codes and source references in the output. Then try the supplied missing-receipt and partial-billing examples. The README names exactly which parts run locally and which connections you still need to build.

The lab treats one fixed order-line ID as the item match. The live ERP adapter must also verify the item itself. Its company selector and saved timestamps are teaching inputs, not a login system or a live connection. The example selects its rule using the stated review date.

Start with a small review queue#

First run beside the existing process. Let finance compare the reports without changing ERP records. Fix recurring field and matching errors. Add policy search only if it helps reviewers answer questions they could not resolve quickly. Expand suppliers and invoice types one group at a time.

The useful result is simple: a person can see what differs, which records prove it, and what to do next. The linked articles explain the technology when the reader wants that detail.

Sources & further reading

  1. Invoice matching rules ↗
  2. Document Intelligence invoice model ↗
  3. Choosing a document reader ↗
  4. OWASP file uploads ↗
  5. OWASP prompt injection ↗