# Logistics Document Pipeline: A Reference Design | QQuantum.ai

> Logistics document pipeline reference design: bills of lading, customs forms and invoices extracted in batches, with typed exception queues and unit costs.

Source: https://qquantum.ai/reference-architectures/logistics-document-pipeline

[Home](https://qquantum.ai) [reference-architectures](https://qquantum.ai/reference-architectures) logistics-document-pipeline

Reference architecture 04

# Document pipelines at volume.

A logistics document pipeline reads bills of lading, customs forms, invoices and delivery notes, extracts the fields and sends them to your ERP or TMS. This illustrative reference architecture is for logistics and supply-chain operations teams. It triages documents before any model call, batches by template, checks fields against each other, and routes damaged, rotated or unexpected documents to typed exception queues for people to clear.

- Batch inference
- Exception routing
- Cost per document

All Reference Architectures →

Introduction transcript. Qubi: Shipping papers pour in all day: crisp scans, crooked photos, smudged faxes. A cheap check comes first: straighten what's crooked, set aside what's unreadable. Papers sharing a template travel together, and one batch run reads them all. Mismatched totals get their own queue, and clean records flow into your systems.

THE PROBLEM

## The demo works on the good scans. The project lives or dies on the bad ones.

Bills of lading, customs forms, invoices and delivery notes arrive continuously, in every condition: crisp PDFs, phone photos taken at an angle, faxes of faxes, forms where the important field is handwritten in a margin. A pilot on a curated sample reports 97% and everyone is delighted.

Then production traffic arrives and the distribution is different. The 3% that fail are not randomly distributed — they cluster on specific trade lanes, specific partners, specific document templates. And because they cluster, they are systematically the documents belonging to particular customers, who now experience the system as broken.

Two things follow. Exception handling is the primary design surface, not a fallback. And unit economics decide viability: a pipeline costing more per document than the clerk it replaces is a science project.

## The design

DOCUMENT PATH

1. 01 Receive email · EDI · upload
2. 02 Triage quality + type score
3. 03 Batch group by template
4. 04 Extract multimodal, batched
5. 05 Validate cross-field checks
6. 06 · Branch / escalation Exception typed queue
7. 07 Emit to ERP / TMS

Lower box = typed exception queueMarker = one document through the pipeline

Triage runs before inference. Scoring a document as unprocessable costs a fraction of a cent; discovering it after a model call costs orders of magnitude more.

- Triage before inference. A cheap classifier scores legibility, orientation, page count and template match first. Rotated pages get rotated; unreadable pages are rejected immediately with a specific reason rather than being sent to an expensive model that will hallucinate something plausible.
- Batch by template, not by arrival. Grouping same-template documents lets a single prompt carry template-specific instructions and few-shot examples, which materially improves accuracy and lets you use a smaller model. Batch APIs then cut per-token cost substantially against synchronous calls, in exchange for latency you usually do not need.
- Validation is cross-field, not per-field. Individually plausible values that are jointly impossible — a total that is not the sum of its lines, a delivery date before a dispatch date — are the highest-yield check available and cost nothing to run.
- Exception queues are typed. "Failed" is not actionable. illegible_scan, unknown_template, arithmetic_mismatch and unsupported_language route to different people with different fixes, and the distribution across those types tells you exactly where to invest next.

pipeline/triage.py PYTHON

```
def triage(doc):
                    class="text-dim"># Cheap checks first — each one avoids a model call.
                    if doc.ocr_confidence < class="text-plasma">0.55:
                        return Exception_(kind=class="text-emerald-data">"illegible_scan", page=doc.worst_page)

                    if doc.detected_rotation:
                        doc = doc.rotate(doc.detected_rotation)

                    template = match_template(doc)
                    if template is None:
                        return Exception_(kind=class="text-emerald-data">"unknown_template")

                    if template.language not in SUPPORTED:
                        return Exception_(kind=class="text-emerald-data">"unsupported_language",
                                          detail=template.language)

                    return Batchable(doc, template=template)
```

Triage is deliberately cheap and dumb. Its job is to keep expensive calls away from documents that cannot succeed.

## Where it breaks

01

### Template drift

A partner silently changes their invoice layout and accuracy degrades for that partner only — invisible in the aggregate. Mitigation: track accuracy per template and per sender, and alert on a per-sender drop rather than a global one.

02

### Exception queues that grow without bound

If exception volume exceeds what the team can clear, the backlog becomes the new bottleneck and you have moved the problem. Mitigation: treat queue depth as a production SLO with an alert, not a report nobody reads.

03

### Batch latency colliding with operations

Batch pricing assumes you can wait. A customs document blocking a container at a port cannot. Mitigation: two lanes — synchronous for time-critical document types, batch for the rest — with the split driven by business rules.

04

### Costs that only look good per document

Per-document inference cost omits retries, exception-handling labour and the engineering time to keep templates current. Mitigation: measure fully loaded cost per successfully emitted record, which is usually well above the naive figure.

## What to measure

01

### Straight-through rate

The share of documents reaching the ERP with no human touch. The headline number, and the one that determines the business case.

02

### Exception mix

Volume by exception type over time. This is the roadmap: whichever type dominates is what to fix next.

03

### Loaded cost per record

Inference, retries, storage and human minutes, divided by successfully emitted records. Compare against the current per-document cost, not against zero.

These are the targets we design against and instrument for; they are not results from a specific deployment. Any figures used above are illustrative.

Questions

## Questions about High-Throughput Document Pipeline.

### How does AI document processing in logistics handle bad scans?

Triage runs before inference: a cheap classifier scores legibility, orientation, page count and template match. Rotated pages are rotated; unreadable ones are rejected straight away with a specific reason rather than sent to an expensive model that might produce something plausible. Whatever still fails lands in a typed queue, such as illegible scan or unknown template, each with its own owner.

### Can time-critical documents wait for batch processing?

No, so the design runs two lanes. Batch inference is cheaper per token in exchange for latency, which suits most invoices and delivery notes; a customs document holding a container at a port goes through a synchronous lane instead. Which document types use which lane is a business rule you set, not a model decision.

### What should we measure before trusting the numbers?

Straight-through rate, the share of documents reaching the ERP with no human touch; the exception mix over time, which tells you what to fix next; and fully loaded cost per successfully emitted record, including retries and human minutes. Track accuracy per sender as well, because one partner changing a template is invisible in the aggregate.

Keep reading

- [Services Intelligent Automation](https://qquantum.ai/intelligent-automation)
- [Industry AI for Manufacturing](https://qquantum.ai/solutions/manufacturing)
- [Reference Document Intelligence](https://qquantum.ai/reference-architectures/clinical-document-intelligence)
