Deterministic AI Data Pipeline
Designed an architectural pipeline where LLMs propose structured candidates into an isolated staging schema. A deterministic rule engine executes mathematical reconciliation, type guards, and duplicate checks before any row can be promoted to the production ledger.
01. Client Context
02. The Problem in the Client's Words
"We tried using AI to extract invoice line items directly into our ERP. But the model would occasionally invent a date format, misread decimal commas, or hallucinate a line item that wasn't on the physical paper. One bad row broke our month-end audit."
03. Constraints & Realities
- Zero corrupted rows permitted in the core production schema.
- Must process mixed scanned PDFs, photographed receipts, and email attachments.
- Cost must remain under $0.05 per processed document.
04. Solution & Architecture Blueprint
Data flow showing intake, deterministic validation barriers, and permanent double-entry audit logging:
05. Data & Security Design
Model service accounts only have INSERT permissions on the `staging_inbox` table. They have ZERO write or update permissions on the production ledger.
The raw input document hash, model prompt tokens, structured extraction JSON, and validation test results are permanently saved in an audit log.
Rigorous validation gate: sum of extracted items must exactly equal invoice total; VAT/tax percentages must match registered rates; supplier tax ID must match active database records.
06. Measured Results (Truth Gate Verified)
Backed by facts.jsonBenchmark test against 2,500 historical invoices with verified human labels
Period: Test evaluation run across 2,500 records
Token cost measured on Gemini Flash / Claude Sonnet with schema compression
Period: Evaluated across 50 production test batches
Database integrity assertions and constraint enforcement
Period: 100% of processed records
07. What Went Wrong & What I Changed
Early versions attempted to make the model "fix" its own mathematical errors in a loop, which drove up token costs without improving accuracy. Replacing the model loop with deterministic Python math validation cut costs by 70% and made the system 100% reliable.
09. What I'd Do Differently
Need a system engineered to this standard?
Book a 20-minute discovery call to review your operational bottlenecks.