Live pipeline · real Claude extraction

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. 1

    Intake & file validation

    Deterministic code

    Type, size, and magic-byte checks. No active content ever reaches a browser context.

  2. 2

    OCR & structured extraction

    AI model

    Document rendered and read; header fields and line items extracted into a strict schema (tool-forced JSON).

  3. 3

    Evidence alignment

    Deterministic code

    Every 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. 4

    Instruction screening

    Deterministic code

    Notes and free-text fields are scanned for instruction-shaped content before anything downstream reads them.

  5. 5

    Arithmetic validation

    Deterministic code

    Line totals, subtotal, tax, and grand total are recomputed from scratch using decimal-safe code — never trusted from the printed figure.

  6. 6

    Supplier identity match

    Deterministic code

    Tax ID first, name as a supporting signal only. Multiple credible matches or a new supplier never auto-resolve.

  7. 7

    Duplicate detection

    Deterministic code

    File hash, normalized identity (supplier + invoice number + date + amount), and line-item fingerprint — runs before any approval routing.

  8. 8

    PO & receipt matching

    Deterministic code

    Supplier, currency, status, and remaining balance compared; SKU takes precedence over description similarity.

  9. 9

    Tolerance & exception rules

    Deterministic code

    Configured, versioned tolerances decide pass/fail — not a confidence score.

  10. 10

    Exception summary drafting

    AI model

    Plain-language explanation generated only from already-verified control results — the model never sees or drafts from unscreened invoice text.

  11. 11

    Decision & routing

    Deterministic code

    Ready / Exception / Duplicate Hold / Blocked, with an approval route and required actions.

  12. 12

    Accounting draft

    Deterministic code

    Idempotent draft-bill creation only. No workflow can execute a payment.

  13. 13

    Human review

    Human

    AP 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 priceLower of 2% or $25 per line
QuantityZero, unless a receipt records the additional quantity
Total invoiceLower of 1% or $50
Tax$0.02 rounding only
Invoice dateCannot precede the PO date
Due dateCannot 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