Skip to content
Boris DupouxFrançais Menu

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.

Evidence level In production

  1. Concept or simulation
  2. Prototype
  3. Field or pilot
  4. In production

used in client deliveries · published scores on synthetic test cases

Compose the recipe

Recipe invoice_multi_doc

  1. Ioio.collectrecipe input✓conforms
  2. Pdpdf.readreads inputs: already produced✓conforms
  3. Sgsegment.documentsreads sources: already produced✓conforms
  4. Clclassify.documentsreads documents: already produced✓conforms
  5. Lmllm.extractreads documents · labels: already produced✓conforms
  6. Vavalidate.idsreads fields: already produced✓conforms
  7. Vavalidate.amountsreads fields: already produced✓conforms
  8. Vavalidate.decidereads fields: already produced✓conforms
  9. Exexport.csvreads documents · status: already produced✓conforms
  10. Gogoogle.sheets.upsertoptional service “sheets”: neutral without it◌inconclusive
  11. Cnconnect.notifyoptional service “notifier”: neutral without it◌inconclusive

Recipe validated on load: Io·Pd·Sg·Cl·Lm·Va₃·Ex·Go·Cn. It takes its place in the Atlas.

A real recipe from the library, multi-document invoice reconciliation: 11 typed steps, validated on load before anything runs. Step names and keys as in the code.

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.

Atlas, “Capture” series: one element per family (connect, google, web, pdf, ocr, layout, audio, vision, vlm, geo, calendar), with its atoms listed below
The Atlas draws the catalogue as a periodic table: here the “Capture” series, one element per family, one tile per atom.
Atlas, “Reconcile” series: match, compare, check, reconcile, validate, rules, events, analytics
The “Reconcile” series: the families that pair, compare, check and decide.

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
StageFamilyAtomsRole
Basecore25pivot types, pipeline, configuration, resilience, files, concurrency
Captureconnect40resilient HTTP, mailboxes, file transfer, cloud storage, read-only ERP source, open data, audit trail
google24mail, sheets, drive, scripts, with resilient execution
web17driver-agnostic web robots: waits, resumable skeleton, forms
pdf9positioned native text, OCR-or-not decision, rendering, page handling, duplicates
ocr9OCR engines
layout3page geometry: lines, columns, deskew, monospace rendering
audio16chunked transcription, segment post-processing, microphone ↔ screen alignment
vision32video streams, detection, tracking, depth, segmentation, calibration
vlm10screen reading with vision-language models
geo11geodesic measures, combined GPS fixes, line-distance filtering, spatial SQL
calendar4public holidays, working days and opening hours
Understandtext32numbers and amounts, dates, normalisation, pattern-based fields, identifiers
segment7pages → logical documents, document numbers, page nature
classify12file name, sender, patterns, TF-IDF, visual and LLM classifiers, cascades
llm24provider-agnostic contract, providers, pool, prompts, structured extraction
anchor5fields and tables located relative to printed labels
kb8traced knowledge base: validated event log folded into a SQLite index
Reconcilematch25EAN/GTIN, indexes, multi-criteria scores, optimal assignment, entity resolution
compare9tri-state, explainable comparators for fields, records and sets
check9generic tri-state checks: totals, VAT, balance, completeness, plausibility
reconcile12set pairing, order → delivery → invoice chains, N-way, ledger and bank matching
validate14rules engine, identifiers, amount consistency, final decision
rules8safe condition language, explainable decision tables, escalation, state machines
events11timestamped events: windows, expected-event watch, sessions, status transitions
analytics18supply-chain analytics: demand, stock-outs, service level, safety stock
Deliverexport8CSV for French Excel, shared workbooks, HTML / Markdown / PDF reports
report6persistable discrepancies, summaries, review queue
render12HTML deliverables: diagrams, charts, maps
diagram6process diagrams: draw.io / BPMN in, Mermaid and BPMN out
Operateops26high availability, scheduled daemon, monitoring, pre-flight checks
qa7editorial 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

Next project Codex — High-Density Archiving of Media on Paper A print-and-scan data channel for 1 to 10 MB media files on ordinary A4 paper, about 383 KB per page; it recovers them byte for byte and prints its own decoder.

Menu

SearchFrançais

Email meLinkedInInstagram