Document extraction at 50K/month
Multi-stage OCR + LLM pipeline for a large German OEM's dealer verification. Collapsed two manual windows totaling 25 days into a rolling 3-day automated cycle at ~$0.20 per document.
The problem
A 20-25 person verification team was four months behind on document intake. The work was mostly mechanical: pull a small set of fields out of each document, cross-check them against a government source of truth, flag mismatches. Volume was ~50,000 documents per month and growing. Manual throughput could not keep up, and every week the backlog added SLA breaches and dealer complaints.
The constraints were tight:
- Auditable accuracy. Every mismatch had to survive governance review.
- Mixed inputs. Scans, PDFs, photos; heavy noise; templates varied by issuing authority.
- No retraining loops. Ops team had ML literacy, not ML engineers.
Architecture
The production stack, split by layer:
S3 stages documents on upload. Lambda orchestrates the pipeline. EC2 hosts PaddleOCR and self-hosted Llama 3.2 for tier-1 extraction. Bedrock handles escalation to a managed LLM when tier-1 confidence dips. MongoDB stores the audit log. Everything is idempotent on the document-id key, which matters once retries become common.
Turnaround
Leadership cared about calendar days, not a model metric.
Cycle completes at day 26 instead of day 45 · dealer windows unchanged, processing windows collapsed from 25 to 6 days.
Dealer upload windows are contractual. What we shortened was the two verification windows that used to burn 15 and 10 days manually. Processing is now rolling - every document flows through as it arrives
- so those 25 days collapsed to about 6. Capacity has plenty of headroom (5000 docs in ~2 days). Human review absorbs ~20% and clears inside the same 3-day window.
Unit economics
At ~6,000 docs per brand per month the pipeline costs about $1,200 to run, or ~$0.20 per document.
Gov API fees dominate. Everything else - compute, storage, observability - fits in eight cents. Human review at 20% escalation is a bounded, predictable line item, not a runaway cost.
LLM cost and OCR cost are the smallest lines on the invoice. Gov API fees are the actual budget. Human review is bounded and predictable because the confidence gate is fixed; if we relaxed it below 0.7 the manual line would blow up.
Failure modes
Documents fail in five ways: garbage OCR (confidence gate catches it, retry at higher DPI with a stricter OCR pass), malformed LLM JSON (schema validator retries once with a stricter prompt), gov API timeout (SQS DLQ with exponential backoff, three attempts), corrupt PDF (rejected at intake, dealer re-uploads), and HITL queue overflow (CloudWatch alarm auto-pauses intake). Every failure lands in the audit log.
Key decisions
1. PaddleOCR over a single end-to-end LLM vision model
We considered throwing GPT-4o at the documents. Two reasons we didn't:
- Cost ceiling. At 50K documents/month, the per-page cost of a vision LLM was ~10× a dedicated OCR step.
- Layout signal. PaddleOCR returns structured layout (tables, bounding boxes, reading order) that we use downstream for field localization. A pure LLM call collapses that information.
OCR does layout extraction; the LLM does field interpretation. Each step is independently testable.
2. Two-tier extraction: small open-weights first, hosted only on retry
Llama 3.2 (locally hosted) handles ~80% of fields cleanly. The hard cases - ambiguous abbreviations, partial scans, low-confidence OCR - escalate to a managed LLM on AWS Bedrock. We picked open-weights for tier 1 because:
- Predictable cost at our volume.
- Privacy posture. Documents contained PII; minimizing what left our VPC was a hard requirement from the legal review.
- Latency. Tier-1 calls land under 800ms p95.
The escalation rule is simple: if the extraction model returns a confidence below 0.7 on any required field, the document goes to tier 2, then if still unresolved to human review.
3. Government API as the source of truth, not the model
Every extracted record is verified against a government API before it lands in the result store. If the API disagrees, the document goes back to manual queue.
This one carried the compliance review.
4. No fine-tuning in v1
We had the data to fine-tune. We chose prompt engineering plus few-shot examples instead, because:
- The win from prompt iteration was visible in days; fine-tuning was weeks.
- Once a fine-tuned model is in production, every prompt tweak becomes a retraining decision.
- The compliance team wanted explainable failures, which prompts give you and fine-tuned weights don't.
We left fine-tuning as a v2 lever.
Outcomes
- ~76% reduction in the two verification windows that used to be manual (25 days combined -> ~6 days rolling), collapsing overall end-to-end cycle time from ~45 to ~26 calendar days
- Four-month backlog cleared
- 5-person team I led across ML, data, and ops
- Sub-800ms p95 on tier-1 extraction; ~3s end-to-end including the gov API roundtrip
- Clean compliance review with audit trails for every flagged case
What I'd do differently
- Schema-first prompting from day one. We retrofitted JSON-schema enforcement after seeing the cost of malformed outputs in the queue. Should have been the first thing.
- A real eval harness, not spreadsheets. Tracking accuracy by document type and field-by-field is non-negotiable at this scale; we ran spreadsheets too long.
- Cache the OCR output aggressively. Most retries re-ran OCR unnecessarily. Easy 10-15% cost reduction we left on the table for the first month.