Architecture
Every stage below is either deterministic code, an AI model call, or a human decision — and the pipeline never lets an AI call stand in for a financial control.
Pipeline
- 1
Intake & file validation
Deterministic codeType, size, and magic-byte checks. No active content ever reaches a browser context.
- 2
OCR & structured extraction
AI modelDocument rendered and read; header fields and line items extracted into a strict schema (tool-forced JSON).
- 3
Evidence alignment
Deterministic codeEvery extracted value is aligned against the OCR/text-layer token positions. A value that can't be found in the document drops to 'uncertain' — the model never emits its own bounding boxes.
- 4
Instruction screening
Deterministic codeNotes and free-text fields are scanned for instruction-shaped content before anything downstream reads them.
- 5
Arithmetic validation
Deterministic codeLine totals, subtotal, tax, and grand total are recomputed from scratch using decimal-safe code — never trusted from the printed figure.
- 6
Supplier identity match
Deterministic codeTax ID first, name as a supporting signal only. Multiple credible matches or a new supplier never auto-resolve.
- 7
Duplicate detection
Deterministic codeFile hash, normalized identity (supplier + invoice number + date + amount), and line-item fingerprint — runs before any approval routing.
- 8
PO & receipt matching
Deterministic codeSupplier, currency, status, and remaining balance compared; SKU takes precedence over description similarity.
- 9
Tolerance & exception rules
Deterministic codeConfigured, versioned tolerances decide pass/fail — not a confidence score.
- 10
Exception summary drafting
AI modelPlain-language explanation generated only from already-verified control results — the model never sees or drafts from unscreened invoice text.
- 11
Decision & routing
Deterministic codeReady / Exception / Duplicate Hold / Blocked, with an approval route and required actions.
- 12
Accounting draft
Deterministic codeIdempotent draft-bill creation only. No workflow can execute a payment.
- 13
Human review
HumanAP and approvers act on exceptions, holds, and blocks — every decision recorded to the audit trail.
What AI does
- Locating candidate fields across varied invoice layouts
- Extracting header data and line items to a strict schema
- Classifying invoice type
- Mapping free-text descriptions to likely PO lines
- Drafting an exception summary from verified control results
- Explaining discrepancies in plain language
What deterministic code decides
- Decimal arithmetic and total recalculation
- Supplier-master comparison, tax-ID and domain normalization
- Exact and fuzzy duplicate rules
- Quantity and unit-price tolerances, PO balance checks
- Approval thresholds and accounting-period rules
- Idempotency, permissions, retry limits
- Instruction-shaped-content screening
The model proposes extracted values. Deterministic code decides whether they satisfy financial controls — never the other way around.
Tolerance policy
Fictional v1 values — all versioned as configuration (current: policy_2026.3).
| Unit price | Lower of 2% or $25 per line |
| Quantity | Zero, unless a receipt records the additional quantity |
| Total invoice | Lower of 1% or $50 |
| Tax | $0.02 rounding only |
| Invoice date | Cannot precede the PO date |
| Due date | Cannot precede the invoice date |
Security & privacy
- Invoice text and QR codes are treated as untrusted data — embedded instructions directed at the model or operator are ignored, never executed.
- File type, size, and magic bytes are validated at intake. A real AV engine is not practical on serverless infrastructure — this is documented as a production deployment requirement, not simulated.
- All tables are RLS-locked to service-role access only, from the first migration.
- Remittance/bank details from an invoice never overwrite the supplier master, ever.
- Bank and tax identifiers are masked in ordinary logs; full document text is kept out of model-provider logs.
- Invoice submitters cannot approve their own invoices.
- No real supplier or financial data appears anywhere in the public portfolio.
Stack & integrations
- App
- Next.js 16 (App Router, TypeScript strict, Tailwind v4) on Vercel
- Data
- Supabase Postgres — NUMERIC money, audit events, jobs; Storage for documents with signed URLs
- Extraction
- Anthropic Claude, native PDF/vision input, tool-forced JSON schema output
- Accounting integration
- QuickBooks Online sandbox (or equivalent) — draft bills only, idempotent, external IDs recorded