54.1 Intelligent Document Processing (IDP) Pipeline
Paper / Scanned / Digital Document
│
▼
┌──────────────┐
│ Pre-processing│ ← Deskew, denoise, contrast enhancement, page splitting
└──────┬───────┘
▼
┌──────────────┐
│ Classification│ ← Which document type is this? (routes to the right extraction template)
└──────┬───────┘
▼
┌──────────────┐
│ OCR Engine │ ← Text extraction with bounding boxes and confidence scores
└──────┬───────┘
▼
┌──────────────┐
│ Layout │ ← Table detection, form field/key-value pair identification,
│ Analysis │ reading order, header/footer detection
└──────┬───────┘
▼
┌──────────────┐
│ Field │ ← Extract targeted fields (names, dates, codes, amounts)
│ Extraction │
└──────┬───────┘
▼
┌──────────────┐
│ Validation + │ ← Cross-reference against known data, business rules, confidence gating
│ Confidence │
└──────┬───────┘
▼
Structured Data → Downstream system of record (ERP, claims, CRM)
54.2 OCR / IDP Tool Comparison
| Tool | Text Accuracy | Table Extraction | Form/KV Extraction | Custom Models | Pricing Model |
|---|---|---|---|---|---|
| Cloud Document Intelligence (managed) | 96%+ | Strong | Strong, prebuilt templates for common forms | Yes | Pay per page |
| Cloud Document AI (managed) | 95%+ | Strong | Strong | Yes | Pay per page |
| Cloud Textract-class service (managed) | 95%+ | Strong | Good (queries API) | Limited custom | Pay per page (cheaper tier) |
| Tesseract (open-source) | 85-90% | Weak (needs external table detection) | Weak | Fully customizable | Free (compute only) |
| Enterprise OCR SDK (e.g., ABBYY-class) | 97%+ | Strong | Strong | Yes | License fee |
| Vision-capable LLM (GPT-4V/Claude Vision) | Variable, strong on reasoning | Good with prompting | Excellent for irregular/edge-case layouts | Via prompting only | Per-image token cost |
Architect’s rule of thumb: Use a managed OCR/IDP service as the default (best accuracy-to-effort ratio, prebuilt table/form parsing). Use open-source OCR (Tesseract) only when data residency/cost forces fully self-hosted processing, and budget engineering time for table/layout post-processing. Use a vision-capable LLM as a fallback for the long tail — documents with unusual layouts, handwriting, or degraded scans that break structured OCR — rather than as the primary pipeline, since per-page LLM vision costs are typically 5-10x a managed OCR call.
54.3 Table Extraction — The Hard Problem
Tables are the highest-friction part of document extraction because layout ambiguity (merged cells, multi-row headers, nested tables, no visible gridlines) breaks naive text-position heuristics.
Table Extraction Techniques (increasing robustness, increasing cost):
1. Gridline detection (CV) → Fast, only works with visible borders
2. Whitespace/column-alignment → Works on borderless tables, brittle to misalignment
clustering
3. ML table-structure models → (e.g., TableTransformer) detects rows/cols/cells
4. Managed cloud table API → Robust, handles merged cells, multi-page tables
5. LLM vision + structured schema → Most robust for irregular tables, most expensive
# Example: extracting a table with a managed Document Intelligence API
result = document_client.analyze_document(
document=file_bytes,
features=["TABLES", "KEY_VALUE_PAIRS"]
)
for table in result.tables:
rows = table.row_count
cols = table.column_count
for cell in table.cells:
print(f"row={cell.row_index}, col={cell.column_index}, "
f"text='{cell.content}', confidence={cell.confidence}")
# Post-process: reconstruct as list-of-dicts keyed by header row
structured_rows = reconstruct_table(result.tables[0])
54.4 Layout Analysis & Field Extraction Strategy
| Document Category | Extraction Strategy | Notes |
|---|---|---|
| Fixed-format forms (standardized government/industry forms) | Prebuilt template models | High accuracy, low engineering cost — use vendor prebuilt models when available |
| Semi-structured business documents (invoices, purchase orders) | Custom-trained layout model or key-value extraction | Requires 50-200 labeled samples per template family |
| Free-form documents (contracts, letters, reports) | OCR + LLM structured extraction | Layout varies too much for template approaches |
| Handwritten / low-quality scans | OCR + LLM vision fallback + human review queue | Confidence-gate aggressively; route low-confidence to humans |
54.5 Confidence-Gated Human-in-the-Loop Design
Extraction Result
│
▼
Confidence Score per Field
│
├── High confidence (>0.95) → Auto-accept, straight to downstream system
├── Medium confidence (0.7-0.95) → Auto-accept + flag for periodic audit sample
└── Low confidence (<0.7) → Route to human review queue with
extracted value pre-filled for fast correction
This confidence-tiered design is what makes IDP economically viable at scale — it lets a small human review team handle only the genuinely ambiguous fraction (typically 5-15% of volume) while automation handles the rest.
Interview Q&A — Section 54
Q1: Compare a managed cloud OCR service against Tesseract for a document processing pipeline. When would you choose each? A: Managed services (Document Intelligence/Document AI/Textract-class) win on accuracy (95-97%+ vs. 85-90%), native table/form structure extraction, and time-to-production — you get bounding boxes, confidence scores, and table reconstruction out of the box. Tesseract is free and fully self-hostable, which matters when data residency rules forbid sending documents to a third-party API, or at extreme volume where per-page vendor pricing becomes the dominant cost driver. In practice: use managed OCR as the default; fall back to self-hosted Tesseract + custom table-structure models only when compliance or cost forces it, and budget significant extra engineering for table/layout parsing that the managed service would have given for free.
Q2: How do you handle table extraction when tables have merged cells, multi-row headers, and no visible gridlines? A: Don’t rely on a single technique. Use a managed table-extraction API or a trained table-structure-recognition model (e.g., TableTransformer-class model) as the primary approach — these are trained specifically to infer row/column/cell structure from visual and textual cues, not just gridlines. For merged headers, post-process by propagating header text down/across merged spans before reconstructing the table as row objects. For the hardest cases (irregular, inconsistent tables), fall back to a vision-capable LLM with a strict output schema and validate row/column counts against expected structure. Always attach a confidence score to reconstructed tables and route low-confidence extractions to human review rather than silently propagating errors downstream.
Q3: Design a confidence-gated IDP pipeline that keeps a human review team’s workload manageable as volume scales 10x. A: Tier every extracted field by confidence score: high-confidence fields auto-flow to the downstream system; medium-confidence fields auto-flow but get sampled into a periodic quality audit; low-confidence fields route to a human review queue with the extracted value pre-populated (humans correct rather than re-key, which is far faster). As volume scales, the review team’s workload scales only with the low-confidence fraction, not total volume — so investing in better extraction models (custom-trained per document type, more training examples) directly reduces headcount need by shrinking the low-confidence tail. Track confidence-threshold calibration over time: if auto-accepted fields show downstream error creeping up, the threshold is miscalibrated and needs retightening.