# Purchase Order Matching Agent

> A 3-way-match agent that reconciles invoice, PO, and receipt, flags price and quantity variances and duplicates, and approves matches within tolerance or escalates.

- **Category:** Supply Chain & Logistics
- **Difficulty:** Advanced
- **Setup time:** 45 min
- **Stacks:** Claude, LangGraph, OpenAI
- **Version:** 2.0.0 (updated 2026-06-21)
- **Source:** https://agent-kits.com/kit/purchase-order-matcher

## Overview

Three-way match done consistently: invoice vs. purchase order vs. goods receipt, with quantities, prices, and terms checked against tolerance.

Catches the costly exceptions: price variances, over-receipts, duplicate invoices, and invoices with no PO — each flag cites the exact variance.

Approves clean matches within tolerance for payment, and routes mismatches and exceptions to a human.

Defensive: never pays a duplicate, never approves over tolerance or without a matching PO and receipt, and flags fraud as evidence, not accusation.

## When to use it

- Accounts payable processes a high volume of PO-backed invoices and the matching work is repetitive.
- You have POs, goods receipts, and invoices the agent can reconcile, plus a tolerance policy.
- You want consistent, documented three-way matching with a clear approval trail.
- You want to auto-clear clean matches and surface only the genuine exceptions, duplicates, and variances to humans.

## When not to use it

- You lack structured PO/receipt/invoice data for the agent to match against.
- You expect it to approve non-PO or over-tolerance invoices autonomously — those require a human.
- Your spend is mostly non-PO/maverick, where there's nothing to three-way match.
- You can't keep approval gates on exceptions, duplicates, and large variances.

## Architecture

- **Invoice intake** — Receives the invoice (vendor, lines, amounts, PO reference) and normalizes it for matching.
- **PO & receipt retrieval** — Pulls the referenced purchase order and the goods receipt that confirms what was actually received — the two documents the invoice is matched against.
- **Three-way match engine** — Compares quantity ordered vs received vs invoiced, unit price invoiced vs PO, and terms, line by line.
- **Tolerance & duplicate checks** — Applies the tolerance policy to each variance and runs a duplicate-invoice check against received/paid history.
- **Approval gate** — A deterministic gate enforces tolerance, the PO+receipt requirement, the duplicate block, and the auto-approval cap; only clean matches pass.
- **Payment routing & holds** — Approves clean matched invoices for payment within limits, holds specific variance lines, and routes duplicates/exceptions to AP with the evidence.
- **Audit trail** — Logs every match decision with the cited variances and outcome for finance controls and audit.

## Files in this bundle

- `system-prompt.md` — the agent's system prompt
- `tools.json` — tool/function definitions the agent expects
- `workflow.md` — step-by-step run loop
- `.env.example` — environment variables to fill in
- `kit.json` — full structured metadata
- `starters/` — minimal starter snippets
- `LICENSE` — Apache-2.0 (code, configuration, and schema)
- `LICENSE-CONTENT` — CC BY 4.0 (specification text and documentation)
- `NOTICE` — attribution and trademark notice
- `run.py` — **runnable demo**: real agent loop with mock tools (`pip install anthropic`, set `ANTHROPIC_API_KEY`, `python run.py`)
- `agentaz.json` / `agentaz.schema.json` — AgentAz™ governance spec + schema

## Implementation notes

- Enforce tolerance, the PO+receipt requirement, the duplicate block, and the approval cap in a deterministic gate; the model matches, the gate controls what can be paid.
- Cite the exact variance (values, percentage, and the tolerance) on every flag — a finding without numbers isn't auditable.
- Make duplicate detection a hard stop on auto-payment; duplicate payments are among the most common and recoverable AP losses.
- Require a goods receipt, not just a PO: paying for goods that were ordered but never received is a classic leakage point.
- Treat suspected fraud as an evidence-based indicator routed to a human, with neutral vendor-facing language.
- Backtest against paid-invoice history with duplicate/over-tolerance approvals as a hard-zero metric before enabling auto-approval.
- Spend the strong model on variance judgment and the escalation decision — a cheaper model can extract and align line items.

## Variations

- **Basic — Match & flag assistant:** Performs the three-way match, applies tolerance, runs duplicate detection, and returns flagged exceptions with cited variances for an AP clerk. No auto-approval.
- **Advanced — Guarded auto-approval:** Auto-approves clean within-tolerance, within-cap matches for payment, holds variance lines, and escalates duplicates, no-PO invoices, and large variances.
- **Enterprise — Governed AP automation:** Adds ERP integration, multi-currency and partial-receipt handling, vendor-level analytics, full audit trails and SLAs, fraud-pattern detection, and tuning from AP outcomes.

## FAQ

**Will it pay invoices automatically?**

Only when the invoice fully matches its PO and goods receipt within tolerance, isn't a duplicate, and is within your configured cap. Anything over tolerance, over cap, without a PO/receipt, or possibly duplicate is held or escalated to a human.

**How does it catch duplicate invoices?**

It checks each invoice against received/paid history on the invoice number and on vendor+amount+PO combinations, and treats a likely match as a hard stop on payment, escalating with the specific matching invoice as evidence.

**What happens on a price or quantity variance?**

It holds the affected line (or invoice) and cites the exact variance against the tolerance — for example, invoiced price 12.5% over the PO against a 5% tolerance — so AP can review or amend the PO.

**Does it require a goods receipt?**

Yes, for auto-approval. Matching only the PO would let it pay for goods that were ordered but never received, so it requires the receipt confirming delivery.

**Does it accuse vendors of fraud?**

No. It surfaces evidence-based indicators (like a duplicate) and routes them to a human, keeping vendor-facing language neutral. It never asserts wrongdoing.

**How do we roll it out safely?**

Start in assist mode where it only recommends, backtest against paid-invoice history to confirm zero duplicate or over-tolerance approvals, then enable auto-approval for clean within-cap matches.


---

© 2026 AgentKits · www.agent-kits.com

**Open source.** Code, configuration, and the AgentAz™ schema are licensed under
**Apache-2.0**; specification text and documentation under **CC BY 4.0** (with
attribution to AgentKits, link to https://www.agent-kits.com). See LICENSE, LICENSE-CONTENT,
and NOTICE in this bundle. "AgentAz" and "AgentKits" are trademarks of AgentKits.

**Flagship reference blueprint.** View the source, AgentAz™ spec, and frozen v1.0 schema
in the public registry: https://github.com/agent-kits/agentaz
Original: https://agent-kits.com/kit/purchase-order-matcher
