# Examples — Purchase Order Matching Agent

## Clean three-way match within tolerance → approve for payment

Invoice matches its PO and receipt on quantity and price within tolerance, under the cap. The routine, payable case.

**Input**

```
Invoice INV-9001 $4,800: 40 units @ $120, PO-551 (40 @ $120), receipt confirms 40 received. Tolerance 5%, cap $10k.
```

**Output**

```
{
  "invoice_id": "INV-9001",
  "decision": "APPROVE",
  "confidence": 0.95,
  "match": { "po": "PO-551", "receipt": "GR-551", "status": "matched" },
  "line_findings": [
    { "line": "40 units widget-A", "check": "qty", "result": "ok", "detail": "ordered 40 / received 40 / invoiced 40" },
    { "line": "40 units widget-A", "check": "price", "result": "ok", "detail": "invoice $120 = PO $120" }
  ],
  "duplicate": { "suspected": false, "evidence": "" },
  "approved_amount_usd": 4800,
  "actions": [ { "tool": "approve_for_payment", "args": { "invoice_id": "INV-9001", "amount_usd": 4800 }, "requires_approval": false } ],
  "vendor_note": "Invoice INV-9001 ($4,800) matched to PO-551 and approved for payment.",
  "escalation": { "needed": false, "reason": "" }
}
```

**Note:** Full three-way match: quantity ordered/received/invoiced all agree, price equals the PO, under the cap, no duplicate. It approves for payment and documents the match. This is the volume the kit clears so AP only touches exceptions.

## Price variance over tolerance → hold the line, cite the variance

Quantities match, but the invoiced unit price exceeds the PO price beyond tolerance. The agent holds and cites the exact variance.

**Input**

```
Invoice INV-9044 $5,400: 40 units @ $135, PO-560 (40 @ $120), receipt confirms 40. Tolerance 5%.
```

**Output**

```
{
  "invoice_id": "INV-9044",
  "decision": "HOLD",
  "confidence": 0.92,
  "match": { "po": "PO-560", "receipt": "GR-560", "status": "partial" },
  "line_findings": [
    { "line": "40 units widget-B", "check": "qty", "result": "ok", "detail": "ordered 40 / received 40 / invoiced 40" },
    { "line": "40 units widget-B", "check": "price", "result": "variance", "detail": "invoice $135 vs PO $120 = +12.5%, exceeds 5% tolerance" }
  ],
  "duplicate": { "suspected": false, "evidence": "" },
  "approved_amount_usd": 0,
  "actions": [ { "tool": "escalate_exception", "args": { "invoice_id": "INV-9044", "reason": "price_variance", "detail": "+12.5% vs PO" }, "requires_approval": false } ],
  "vendor_note": "Invoice INV-9044 is on hold: the unit price ($135) is 12.5% above the PO price ($120), beyond our 5% tolerance. AP will review.",
  "escalation": { "needed": false, "reason": "Price variance +12.5% exceeds tolerance — needs AP review or a PO amendment." }
}
```

**Note:** Quantities and receipt are fine, but the price is 12.5% over the PO against a 5% tolerance — so the agent holds rather than pays, and cites the exact variance and threshold. This is the line-level catch that prevents silent overbilling.

## Duplicate invoice / no PO → escalate, never pay

An invoice has no PO reference and looks like a duplicate of one already paid. The agent refuses to approve and escalates with evidence.

**Input**

```
Invoice INV-9100 $7,200, vendor Acme, no PO referenced. duplicate_invoice_check finds INV-8841 (Acme, $7,200, PO-540) already paid last month.
```

**Output**

```
{
  "invoice_id": "INV-9100",
  "decision": "ESCALATE",
  "confidence": 0.8,
  "match": { "po": "missing", "receipt": "missing", "status": "unmatched" },
  "line_findings": [],
  "duplicate": { "suspected": true, "evidence": "Matches INV-8841 (Acme, $7,200, PO-540) already paid 2026-05" },
  "approved_amount_usd": 0,
  "actions": [ { "tool": "escalate_exception", "args": { "invoice_id": "INV-9100", "reason": "duplicate_and_no_po", "evidence": ["INV-8841"] }, "requires_approval": false } ],
  "vendor_note": "Invoice INV-9100 is on hold pending review — it has no PO and appears to match a previously paid invoice. AP will follow up; this may be a re-send.",
  "escalation": { "needed": true, "reason": "No PO and a likely duplicate of paid INV-8841 — must not be auto-paid." }
}
```

**Note:** The defining defensive case: no PO to match against and strong duplicate evidence (same vendor, amount, and PO as an already-paid invoice). The agent treats it as a hard stop on payment, escalates with the specific matching invoice, and keeps the vendor note neutral — it may be an honest re-send. Duplicate and non-PO invoices are exactly where automated payment goes wrong.
