Applied Research04 / 14
Explainable Processing Atoms for Documents & Data
A Python library that consolidates production document-processing systems into small, typed, traceable atoms, mapped in a generated Atlas and assembled into validated recipes that return tri-state, explainable verdicts.
Recipe invoice_multi_doc
- Io
io.recipe input✓conformscollect - Pd
pdf.reads inputs: already produced✓conformsread - Sg
segment.reads sources: already produced✓conformsdocuments - Cl
classify.reads documents: already produced✓conformsdocuments - Lm
llm.reads documents · labels: already produced✓conformsextract - Va
validate.reads fields: already produced✓conformsids - Va
validate.reads fields: already produced✓conformsamounts - Va
validate.reads fields: already produced✓conformsdecide - Ex
export.reads documents · status: already produced✓conformscsv - Go
google.optional service “sheets”: neutral without it◌inconclusivesheets. upsert - Cn
connect.optional service “notifier”: neutral without it◌inconclusivenotify
Recipe validated on load: Io·Pd·Sg·Cl·Lm·Va₃·Ex·Go·Cn. It takes its place in the Atlas.
Document checks rebuilt from small typed atoms, so that every verdict says conforms, discrepancy or inconclusive, with a named reason a human can contest.
Key figures
- expected signals of one injected discrepancy
- 5 / 5
- 1 synthetic dossier
- exact fields in LLM extraction
- 28 / 28
- 4 synthetic invoices
- atoms in 32 families
- 459
- code size, not result
- recipes validated before execution
- 17
Abstract
At Capture, several document-reconciliation robots written for retailers each solved the same sub-problems in their own way, with their own bugs. I consolidated those codebases into a library of single-responsibility atoms, assembled into recipes validated before they run. Every verdict says conforms, discrepancy or inconclusive, with a named reason, and LLM extractions are checked word for word against the source.
Key notions
- tri-state verdicts
- verbatim grounding
- single-responsibility atoms
- cross-document reconciliation
- generated code atlas
Where it started
At Capture we built several document-reconciliation robots for retailers, one after another. The need was the same every time: improve the accounting position by checking invoices against delivery notes and orders, from PDFs, scans, CSV files and emails. Each robot had been written for one client. Over time I ended up with several codebases that solved the same sub-problems, each in its own way, with their own bugs.
I wanted to consolidate them, and to take the opportunity to answer a question that had bothered me from the start: can a document check be automated so that a human can audit and contest every verdict? The result is a Python library made of small typed atoms, each traced back to the production code it came from, and that library is what goes into client deliveries today.
What I built
flowchart TB
A["Input documents<br/>PDF, scans, CSV, mail"] --> B{"Native text or OCR?"}
B -- "native" --> C["Positioned native text"]
B -- "scan" --> D["OCR"]
C --> E["Segmentation & classification"]
D --> E
E --> F["LLM extraction<br/>+ verbatim check"]
F --> G["Cross-document reconciliation<br/>invoice · delivery note · order"]
G --> H["Tri-state verdict<br/>+ reason + trace"]
H --> I["Report / human review"]Each atom has one responsibility, typed inputs and outputs, and no global state. A pipeline is a composition of atoms, written in code or declared as a recipe; the recipe is validated when it loads, before anything runs. The 459 atoms follow the chain in five stages, on top of a small typed core of 25 atoms:
- Capture (175 atoms): mailboxes, web, PDF, OCR, audio, vision, geodata;
- Understand (88): text and amounts, segmentation, classification, LLM extraction;
- Reconcile (106): matching, comparison, checks, rules, reconciliation chains;
- Deliver (32): exports, reports, charts, diagrams;
- Operate (33): availability, monitoring, non-regression.
They are assembled into 17 validated recipes, such as invoice reconciliation or meeting transcripts.
Every comparison returns a verdict with three states, conforms, discrepancy or inconclusive, with a named reason and a trace. A missing or unreadable value is inconclusive, never an anomaly, and it is still counted. When an extraction is handed to an LLM, its output is first validated against a schema, then each value is looked up word for word in the source text; an invented or altered value is flagged. LLM verdicts stay downstream of deterministic rules.
Each ported atom is traced back to the production code it came from, and an Atlas, generated from the code itself, draws the whole catalogue.


Sources: Atlas generated from the library’s own code; interface in French
What the numbers say
All the scores come from synthetic test cases with known ground truth. In reconciliation, document types and fields are recognised 14 out of 14 on two dossiers; a compliant dossier raises no error-level discrepancy (warnings are not counted), and a dossier with one injected discrepancy raises all 5 expected signals. In extraction, the JSON is valid 4 out of 4, all 28 fields of four invoices are exact, and all 16 synthetic alterations are rejected by the word-for-word check.
OCR reaches a recall of 0.94 on a degraded label of 17 words, and table reading 100 % exact cells on one synthetic table (95 % in monospace). Each of the 17 recipes has at least one end-to-end test with real engines.
What it is worth, and what is missing
These scores are synthetic and tiny: one or a few dossiers each, a single run, with a local 8B model. That model once called a +50 % quantity gap “minor”. The word-for-word check is true by construction: it is bound to reject an altered value, and it does not catch a real value placed in the wrong field (1 case out of 8). Only about 41 % of the modules are exercised end to end.
Real documents are still pending. The first runs, about 10 to 25 cases per recipe, are mixed and partly unreviewed: text extraction is good, duplicate detection and document splitting are weak. I will publish the scores once they have been reviewed.
Technical details
| Stage | Family | Atoms | Role |
|---|---|---|---|
| Base | core | 25 | pivot types, pipeline, configuration, resilience, files, concurrency |
| Capture | connect | 40 | resilient HTTP, mailboxes, file transfer, cloud storage, read-only ERP source, open data, audit trail |
| 24 | mail, sheets, drive, scripts, with resilient execution | ||
| web | 17 | driver-agnostic web robots: waits, resumable skeleton, forms | |
| 9 | positioned native text, OCR-or-not decision, rendering, page handling, duplicates | ||
| ocr | 9 | OCR engines | |
| layout | 3 | page geometry: lines, columns, deskew, monospace rendering | |
| audio | 16 | chunked transcription, segment post-processing, microphone ↔ screen alignment | |
| vision | 32 | video streams, detection, tracking, depth, segmentation, calibration | |
| vlm | 10 | screen reading with vision-language models | |
| geo | 11 | geodesic measures, combined GPS fixes, line-distance filtering, spatial SQL | |
| calendar | 4 | public holidays, working days and opening hours | |
| Understand | text | 32 | numbers and amounts, dates, normalisation, pattern-based fields, identifiers |
| segment | 7 | pages → logical documents, document numbers, page nature | |
| classify | 12 | file name, sender, patterns, TF-IDF, visual and LLM classifiers, cascades | |
| llm | 24 | provider-agnostic contract, providers, pool, prompts, structured extraction | |
| anchor | 5 | fields and tables located relative to printed labels | |
| kb | 8 | traced knowledge base: validated event log folded into a SQLite index | |
| Reconcile | match | 25 | EAN/GTIN, indexes, multi-criteria scores, optimal assignment, entity resolution |
| compare | 9 | tri-state, explainable comparators for fields, records and sets | |
| check | 9 | generic tri-state checks: totals, VAT, balance, completeness, plausibility | |
| reconcile | 12 | set pairing, order → delivery → invoice chains, N-way, ledger and bank matching | |
| validate | 14 | rules engine, identifiers, amount consistency, final decision | |
| rules | 8 | safe condition language, explainable decision tables, escalation, state machines | |
| events | 11 | timestamped events: windows, expected-event watch, sessions, status transitions | |
| analytics | 18 | supply-chain analytics: demand, stock-outs, service level, safety stock | |
| Deliver | export | 8 | CSV for French Excel, shared workbooks, HTML / Markdown / PDF reports |
| report | 6 | persistable discrepancies, summaries, review queue | |
| render | 12 | HTML deliverables: diagrams, charts, maps | |
| diagram | 6 | process diagrams: draw.io / BPMN in, Mermaid and BPMN out | |
| Operate | ops | 26 | high availability, scheduled daemon, monitoring, pre-flight checks |
| qa | 7 | editorial non-regression, simulation replay, inter-annotator agreement |
Stack
Python · Pydantic · PyYAML · PaddleOCR · Ollama · Mistral / Anthropic / OpenAI APIs · pytest · mypy · ruff
Topics
Licensed under CC BY 4.0
How to cite
Boris Dupoux. (2026). Explainable Processing Atoms for Documents & Data. borisdupoux.com. https://borisdupoux.com/research/processing-atoms/
Related content
Back to Applied ResearchPreviousHandheld Video to Photogrammetry and Gaussian Splatting
