Direct Answer
A production multimodal document pipeline is not “send an image to a vision-language model and parse JSON.” It is a chain of versioned transformations from an immutable source to evidence-linked output, with explicit contracts for coordinates, reading order, authorization, quality, retries, deletion, and review.
Current systems span several architectures. OmniDocBench evaluates both modular pipelines and end-to-end VLMs across text, layout, tables, formulas, reading order, document types, and attributes. The official PaddleOCR-VL pipeline itself combines layout analysis with region-level VLM recognition. These examples invalidate a simplistic “old OCR pipeline versus one native model” story.
Begin with an Output Contract
Define what downstream code needs before selecting a model.
| Workload | Required artifact | High-impact failure |
|---|---|---|
| Search ingestion | ordered text spans with source IDs | missing or duplicated passages |
| Invoice processing | typed fields linked to page regions | wrong amount, currency, or supplier |
| Contract review | clauses, tables, footnotes, page references | lost exception or mismatched version |
| Visual question answering | answer, supporting regions, abstention | fluent answer without visual evidence |
| Training-data creation | normalized content plus lineage | silent contamination or license loss |
A schema can prove that total is a decimal string. It cannot prove that the string came from the invoice total rather than a subtotal, that the currency is correct, or that the caller may access the document. Those are semantic, evidence, and authorization contracts.
Reference Architecture
The canonical artifact model is the architectural center. Model-specific outputs should be adapters into this model, not formats that leak throughout the application. A document transformer may normalize or enrich an artifact, but it must preserve provenance and deletion lineage.
At minimum, preserve:
- source digest, tenant, retention class, and source revision;
- page number, render dimensions, orientation, and every coordinate transform;
- element ID, type, bounding box, reading-order predecessor, and recognized text;
- engine name, artifact digest, runtime revision, prompt or config revision;
- field value, normalization, evidence element IDs, and validation status;
- attempt, latency, error class, and whether the result was automatic or reviewed.
Architecture Families
Modular document pipeline
A modular pipeline separates page rendering, layout detection, reading order, OCR, tables, formulas, and semantic extraction. Each stage can use a specialized document loader, deterministic algorithm, computer vision model, or document VLM.
This design offers inspectable intermediate artifacts and selective reprocessing. It also creates compatibility contracts: coordinate systems can drift, region crops can lose context, reading order can be wrong, and an upstream deletion must reach every derivative.
End-to-end document VLM
An end-to-end model maps a page or document directly to text, Markdown, JSON, or another structured representation. It can preserve broad visual context and remove some handoffs, but “end-to-end” does not remove preprocessing, serving, validation, provenance, or review.
The LLaVA paper connects a vision encoder with an LLM through visual instruction tuning. Qwen2-VL introduces dynamic resolution and multimodal positional encoding. These are specific architectures, not proof that every VLM has the same encoder, connector, token count, or training pipeline.
Hybrid and routed pipeline
A hybrid routes pages or fields to different paths. Examples include:
- born-digital text through a parser while scanned pages use OCR;
- simple regions through a compact recognizer while difficult tables use a VLM;
- an end-to-end parser with a separate layout detector for evidence coordinates;
- a fast first pass followed by review or a second model only on failed checks.
Routing adds its own error surface. A cheap route is not useful if it silently misclassifies the difficult slice, and a fallback is not reliable if the same dependency, prompt, or corrupted input causes both paths to fail.
Stage-by-Stage Engineering
1. Ingest immutable source bytes
Hash the original bytes before transformation. Record media type from actual parsing, not only a file extension. Enforce byte, page, pixel, decompression, and processing-time limits. PDFs can contain scripts, attachments, malformed objects, or unexpectedly expensive content; images can trigger decoder vulnerabilities or memory exhaustion.
Store a content-addressed source reference. Every derivative should point back to that digest so a later audit can reproduce which bytes produced a field.
2. Render pages with an explicit coordinate system
Define origin, axis direction, units, page rotation, crop, and scale. Keep transforms reversible:
source PDF coordinates
-> rendered page pixels
-> model input crop
-> normalized output coordinates
-> source-page evidence box
Rounding at each hop compounds error. Preserve floating-point transforms and round only when rendering a UI or serializing a consumer-specific format.
3. Detect layout and reading order
Layout is not cosmetic. A parser must distinguish headings, paragraphs, lists, tables, formulas, figures, captions, headers, footers, and marginal notes, then establish reading order. Multi-column pages, spanning tables, footnotes, and rotated annotations frequently break naive top-to-bottom sorting.
Evaluate region detection and reading order independently. A page can have low text edit distance while linking a caption to the wrong figure or placing a footnote in the middle of a paragraph.
4. Recognize content without discarding evidence
For each element, retain both normalized content and its source region. Text recognition, table reconstruction, formula transcription, and chart interpretation need different metrics and failure handling.
Do not turn a VLM's generated “confidence: 0.98” into an acceptance probability. If a model or OCR engine emits scores, calibrate them against labeled data from the same document families and deployment version. Hard invariants such as checksum, required type, balanced totals, or valid date ranges remain separate from learned confidence.
5. Normalize conservatively
Normalization should be reversible and typed:
- retain raw text beside normalized text;
- distinguish missing, unreadable, not applicable, and explicitly blank;
- preserve locale and currency before parsing numbers;
- retain table spans and merged-cell structure;
- do not silently repair an ambiguous formula, date, or identifier.
Every inferred correction should record the original value, transformation, confidence source, and review status.
6. Link fields and answers to evidence
A structured field should carry one or more source spans or regions. An answer should identify the source revision and supporting elements. Validate both the value and its evidence location.
For high-impact fields, compare independent signals: text region, table structure, arithmetic constraints, document-level context, and an authoritative business record where available. Agreement reduces uncertainty but does not create authorization.
Evaluation That Matches the Document
One “OCR accuracy” number hides the failures users experience. Build a matrix:
| Dimension | Example metric or check |
|---|---|
| Text | character or word error rate by language and font |
| Layout | detection precision/recall and region IoU |
| Reading order | pairwise or sequence-order errors |
| Tables | structure and cell-content metrics |
| Formulas | normalized expression or rendered equivalence |
| Fields | precision, recall, exact match, normalization errors |
| Evidence | source-region coverage and localization error |
| End-to-end | accepted-document rate and harmful-field error rate |
| Operations | p95 latency, throughput, queue time, retry and OOM rate |
Use document slices that reflect production: born-digital, scan, phone camera, skew, warp, low light, handwriting, dense newspaper, mixed languages, formulas, tables, stamps, and adversarial content. Public benchmarks help compare published systems; private acceptance sets decide whether your system ships.
Capacity and Cost Without Fictional Benchmarks
Do not copy a table that assigns one OCR percentage, latency, price, or GPU requirement to a model name. Record the complete measurement contract:
- exact model or API snapshot and license;
- input resolution, page count, visual-token policy, and output length;
- quantization, precision, runtime, accelerator, memory, batch, and concurrency;
- preprocessing, prompt, schema, retries, cache policy, and fallback;
- warmup, sample count, p50/p95/p99, energy or provider bill;
- quality on the same page and field slices.
Batching can improve throughput but can worsen queueing and tail latency. Downsampling can save compute but erase small text. Perceptual caching can return another document's sensitive or outdated result unless keys include tenant, source digest, processing contract, and deletion state.
The useful economic metric is cost per accepted page or document, including rejected work, retries, review, storage, and idle capacity.
Reliability, Security, and Recovery
Treat every document, OCR string, VLM output, and embedded instruction as untrusted input.
- authorize the source before processing and before every downstream retrieval;
- isolate decoders and self-hosted model runtimes from production credentials;
- prevent model output from choosing arbitrary URLs, file paths, recipients, or tools;
- bind caches to tenant, source digest, model/config revision, and policy;
- make retries idempotent and represent
outcome_unknownexplicitly; - propagate deletion to pages, crops, text, embeddings, caches, traces, and review queues;
- retain only the minimum source content needed for debugging under a documented policy.
For the field-level admission and visual prompt-injection boundary, see the AI image understanding pipeline. This article focuses on the broader document transformation system.
Runnable Go Lineage Validator
The following standard-library program checks that a pipeline result forms one continuous, versioned chain. It detects a missing engine revision, an input/output mismatch, a duplicate stage name, or a stage that produced no output digest.
package main
import (
"errors"
"fmt"
)
type Stage struct {
Name string
Engine string
InputDigest string
OutputDigest string
}
func validateLineage(sourceDigest string, stages []Stage) error {
if sourceDigest == "" {
return errors.New("source digest is required")
}
seen := make(map[string]bool, len(stages))
expectedInput := sourceDigest
for index, stage := range stages {
if stage.Name == "" || stage.Engine == "" {
return fmt.Errorf("stage %d lacks name or engine revision", index)
}
if seen[stage.Name] {
return fmt.Errorf("duplicate stage %q", stage.Name)
}
if stage.InputDigest != expectedInput {
return fmt.Errorf(
"stage %q input %q does not match %q",
stage.Name,
stage.InputDigest,
expectedInput,
)
}
if stage.OutputDigest == "" {
return fmt.Errorf("stage %q has no output digest", stage.Name)
}
seen[stage.Name] = true
expectedInput = stage.OutputDigest
}
return nil
}
func main() {
stages := []Stage{
{Name: "render", Engine: "renderer@sha256:11aa", InputDigest: "src:8f4c", OutputDigest: "pages:91bd"},
{Name: "layout", Engine: "layout@sha256:22bb", InputDigest: "pages:91bd", OutputDigest: "regions:37ce"},
{Name: "recognize", Engine: "vlm@sha256:33cc", InputDigest: "regions:37ce", OutputDigest: "artifact:5ad1"},
}
if err := validateLineage("src:8f4c", stages); err != nil {
panic(err)
}
fmt.Printf("lineage=valid stages=%d final=%s\n",
len(stages),
stages[len(stages)-1].OutputDigest,
)
}
Expected output:
lineage=valid stages=3 final=artifact:5ad1
This validator proves continuity of declared artifacts, not the truth of extracted content. Pair it with task-specific evaluation and source-region checks.
Release Checklist
- Freeze source fixtures, labels, document slices, and acceptance policy.
- Pin every parser, model, prompt, schema, renderer, and runtime artifact.
- Compare modular, end-to-end, and routed candidates under one protocol.
- Verify coordinate transforms and evidence links, not only final text.
- Test malformed files, prompt injection, unauthorized documents, cancellation, and duplicate delivery.
- Measure accepted quality, review coverage, tail latency, and cost together.
- Shadow the new pipeline, then canary by document slice with rollback.
Frequently Asked Questions
Should OCR and VLM results be averaged into one confidence score?
Not by default. The scores may have different meanings, calibration sets, and failure modes. Keep hard validation, OCR or detector scores, model confidence, and evidence checks separate until a labeled dataset demonstrates a valid calibration method.
Is an end-to-end document model simpler?
It can reduce application-level stages, but the complete system still needs decoding, input policy, serving, evidence, validation, observability, retries, review, and deletion. Compare operational simplicity across the full lifecycle, not the number of model calls.
How should a team choose input resolution?
Sweep resolution on representative slices and record visual tokens, memory, latency, small-text errors, table structure, and cost. A fixed maximum dimension is not portable across models, page sizes, or tasks.
Can similar document images share cached output?
Only under a narrowly tested equivalence contract. Perceptual similarity does not prove identical amounts, names, signatures, or permissions. Prefer exact source-digest caching, and include tenant, processing revision, and deletion state in the key.
What should happen when a stage times out?
Record the attempt as incomplete, cancel downstream work where possible, and reconcile any durable state before retrying. A retry must use an idempotency key and must not silently combine artifacts from different attempts.