Accounts payable · Case study
Vendor Invoice Reconciliation
Upload one vendor invoice or a whole batch. The agent extracts each, finds the matching purchase order, contract and vendor-master record, applies an accounts-payable policy, and returns Approved, Flagged or Rejected with explicit discrepancy reasons.
- Role
- Designer and builder
- Stack
- Python, Streamlit, Gemini / Groq, Docker
- Data
- Synthetic, for demonstration
- Status
- Working prototype
The problem
Accounts payable has to catch duplicates, over-billing, wrong tax and freight treatment, contractor expense overruns and vendor fraud, usually by hand and under time pressure. Each check needs the invoice, the PO, the contract and the policy side by side.
How the agent works
- Goal: audit an invoice for full financial and policy compliance.
- Plan: extract fields, look up the PO, contract, vendor and policy, load invoice history, cross-check, run a policy review, then give a verdict. Every step is recorded in the report's trace.
- Memory: a reference store of structured PO, contract and vendor records. Past audits double as invoice history.
- Executor: deterministic policy rules. Only these rules can produce a Rejected verdict.
- AI review: an LLM reads the invoice, PO, contract and policy for anything the rules cannot see. Its findings are advisory, capped at warning level. It can add findings but never reject or downgrade.
The same principle as my P-card pipeline: rules decide, AI advises. It keeps outcomes explainable and defensible.
What the rules check
- Three-way match, with price, quantity and total tolerances
- Cumulative billing and not-to-exceed limits on a PO
- Freight and sales-tax rules, contractor T&E limits, milestone billing
- Duplicate and reprint detection
- Vendor-master and bank-fraud red flags
- Contract validity, payment terms and tiered approval authority
Thresholds live in a configuration file, so a finance team can tune tolerances without touching code.
Built for real inputs
Invoices can be PDFs or images, including scanned, image-only documents. Calls request structured JSON from Gemini first and fall back to Groq on any failure, with text extraction for PDFs and a vision model for images. The app has a multi-file uploader, a batch summary table with CSV export, and a per-invoice audit dashboard.
Every audit is saved as JSON, and later audits read those to catch duplicate invoices and cumulative over-billing. Batches are processed in filename order so an original is on record before its reprint.
Testing
The repo ships 13 test invoices covering clean, duplicate, fraud, over-billing, T&E and scanned cases, plus a unit test suite. All vendors, contracts and invoices are synthetic.