Daniele Del GuercioPublic summary of technical note TN-01, 4 November 2026

Checking supplier documents before the ERP write

In practice, quality certificates and invoices arrive from suppliers as PDF files or scans; in this run they are synthetic records. A model reads them, and the values go into the ERP: batch numbers, quantities, test results, amounts. A reading that is right on 98.3% of fields can still put wrong records into the system of record. This page describes a check that runs before every ERP write, and what it did in that run.

1. What was run

One command generates 12 weeks of synthetic data for 3 sites and 12 suppliers: purchase orders, delivery notes with batch and heat numbers, 479 quality certificates and 392 invoices, some of them marked as scans. A simulated model reads each document. Its errors are injected and logged, so the right value of every field is known and each result can be scored against it. Each decision is then logged, and each passed record is written into a simulated ERP while timeouts, outages and crashes are injected.

2. Flow

  1. DocumentCertificate or invoice, with a text layer or marked as a scan.
  2. ReadingThe model fills a fixed schema and cites where it read each value.
  3. RulesSchema, format, value found at its cited source, cross-check against ERP data, invoice matched to deliveries, a second check on invoice totals.
  4. PersonConfirms the critical fields. Only after 20 confirmations in a row with nothing corrected can a supplier's records skip human confirmation on a document type; scanned records never do, and an alert sends that supplier's or site's records of that type back to human confirmation.
  5. ERP writeEvery decision is logged first. Only an explicit pass is written, through a journal and with an idempotency key.

A record that fails a step is not written. It is held with the reason and an owner, for example the buyer, incoming quality or accounts payable.

3. Results

Wrong records written to the ERPWithout the check (as read)With the check (rules, then a person)
This run, 871 records1340 (144 held, each with a reason and an owner)
39 runs on other random data: median (lowest to highest)149 (120 to 185)1 (0 to 3), none in a critical field

Main run: seed 17, 12 weeks, 3 sites, 12 suppliers, 871 documents (479 certificates, 392 invoices). After the rules: 727 passed (130 written without human confirmation, 597 with critical fields confirmed by a person) and 144 held, each with the reason and an owner.

As read: 98.3% of 9,102 fields were read correctly, yet 134 records would be written wrong: 91 certificates, and 43 invoices approved by a plain invoice-to-order match (18 booked against the wrong delivery, 17 with a misread critical field, 8 billed before the goods arrived).

With the check: of the 148 records that, by the known truth, must be held or corrected (not the same set as the 134 above, which also depends on the plain invoice-to-order match), the rules hold 138 and the person confirming critical fields corrects 10. Known wrong invoice matches among the 338 invoices passed: 0 (over the 39 runs: 0 in every run). Also held: 6 correct records (false holds), waiting for a person to release them.

4. One record from the run

Certificate C-S03-0577 from supplier S03, for order 4500010280. The format check passes. The cross-check against the delivery notes of the order fails, so the record is held for incoming quality. The reason, as the check wrote it:

erp: batch 48213 is not on a delivery of order 4500010280 (delivered: 48231); it is on no delivery note

5. Drift alerts

One supplier changes its certificate template in week 7: its rejection rate raises an alert after 7 days. Certificates at one site switch language in week 9: alert after 14 days. False alerts in 12 weeks: 0. An alert sends that supplier's or site's records of that document type back to human confirmation.

Over the 39 other runs (seeds 1 to 40 except 17): the template alert came after a median of 7 days (39 in the worst run), the language alert after a median of 3 days (21 in the worst run); false alerts 0 to 4 per run (median 0).

6. Controls and how each is tested

ControlProtects againstHow it is tested
Fail-closedA record written by default after an error, a missing field or an unclear result.Tests inject an exception into each check function and raise twelve exception types, built-in and custom; they also feed in an unusable check result, remove each critical field, give unparseable values and an unknown document type. In every case the record is held, and only an explicit pass is written. A keyboard interrupt is not caught: it stops the run and is never turned into a pass. A record whose check raises an exception is held and the run goes on; a decision that cannot be logged stops the run before its ERP write. Over the full run, no held decision reaches the ERP.Tests: 19 (test_fail_closed.py 17, test_write_path.py 2)
Cross-check against ERP dataA value that is well formed but wrong, such as a batch number with two digits swapped or a value taken from the wrong table row.The example above and every wrong-row case pass the format check and are held by the cross-check. Every defect injected into a document with a text layer is held, except a day and month swap (see limits), and so is every document seeded with a conflict against the ERP data, such as a supplier typo, a duplicate invoice or a price change.Tests: 13 (test_prototype.py)
Each value traced to its cited sourceA value the model reports that is not at the place in the document it cites, such as a heat number read as the batch number.A value that is not what its cited table cell says fails the trace, and so does a value cited from the heat column as a batch number; in the run every heat number taken as a batch number is flagged with a reason that names the cause. Numbers written in several formats, and ambiguous dates (both readings are kept), are tested.Tests: 4 (test_prototype.py)
Second channel on invoice totalsA misread amount that the main check lets through.The total read is compared with the total recomputed from the lines (quantity x unit price). A difference of more than 0.01 (one cent) holds the invoice even when the main check passed it, so per-line rounding that the main check tolerates is caught. On seed 17 it flags exactly the invoices with a misread total, unit price or quantity, 21 in the run and all held, and no correct invoice.Tests: 4 (test_fail_closed.py)
Invoice matched to received, uninvoiced deliveriesPaying for the wrong delivery, paying twice, paying before the goods arrive.A partial delivery invoiced out of order is matched to the right delivery, where a plain invoice-to-order match books the oldest one; a delivery already invoiced, the same invoice number twice, billing before receipt and a total that is not the sum of its lines are held; two deliveries that fit equally go to the buyer.Tests: 9 (test_prototype.py)
A person on critical fieldsMisreads the rules cannot see, such as an in-spec test value misread on a scan.Short scripted runs check the rule record by record: a supplier's records on a document type skip human confirmation after 20 confirmations in a row with nothing corrected, and not before. A correction, or a wrong value found in the weekly hand check, ends the skip and starts the count again; a record held by the rules neither counts nor resets it. A scan still goes to the person, even when the supplier's other records skip human confirmation. Over the whole main run, no scanned record skips it, and an independent replay of the rule on the run's decisions finds every skip allowed.Tests: 9 (test_prototype.py)
Rejection rate per supplier and site, with an alertA silent change at the source, such as a new certificate template or a new language.After an alert, no record of that supplier or site on that document type skips human confirmation until the alert window ends, even after 20 confirmations with nothing corrected inside the window. A supplier alert also starts the count of that supplier and document type again; a site alert does not. The hold reasons name the cause. In the run: alerts after 7 and 14 days, 0 false alerts.Tests: 6 (test_prototype.py)
Idempotent ERP writesDuplicate ERP rows from retries and timeouts.The key is the SHA-256 of the normalised record, so equivalent forms of the same record give one key. The same write delivered 3 times gives one ERP row, against an ERP that enforces the key and against one that only allows a lookup. Against the lookup-only ERP, 3 restarts give one row, a retry after a timeout that came after the ERP had committed gives one row, and timeouts before commit are retried with growing waits. A randomised run of faults and crashes ends with no duplicate and no lost record. In the full run the simulated ERP, which does not deduplicate by itself, timed out 29 times before and 17 times after commit: 727 rows for 727 passed records, 0 duplicates.Tests: 9 (test_erp_writer.py 7, test_write_path.py 2)
Journal before the writeRecords lost or written twice if the process stops between the decision and the write.The intent is written to a journal and flushed to disk before the ERP is called. Tests simulate a crash before the journal entry, between the decision and the write, and between the ERP commit and the done mark: after the restart each record is written once. The full run had 3 simulated crashes, one at each of these points, and lost nothing and wrote nothing twice; a run with 10 simulated crashes did the same.Tests: 6 (test_erp_writer.py 4, test_write_path.py 2)
Source document hash, from receipt to the ERP rowLosing track of which document a written value came from, or a document changed after receipt.The SHA-256 of each source document record, taken at receipt, is stored with its decision and reaches its ERP row. Over the full run all 871 logged decisions and all 727 ERP rows carry their document's hash. A document changed after receipt is held.Tests: 4 (test_fail_closed.py 2, test_write_path.py 1, test_erp_writer.py 1)
Chained decision log with HMAC tagsA decision changed, removed, reordered or added after the fact.Each row carries the SHA-256 of the previous row and an HMAC-SHA256 tag, both recomputed independently in a test. HMAC-SHA256 is a keyed hash, not a public-key signature: whoever can verify the log also holds the key. The verifier finds a modified, a deleted, a moved and an inserted row, and a wrong key; rows cut off the end are found against the anchor (row count and last hash). The key is never written to the log, a key file inside the output folder is refused, and the key is in no output file of the run. All 871 decisions of the full run are in the log in order, and the log verifies against its anchor.Tests: 13 (test_ledger.py 10, test_write_path.py 3)
Reconciliation after the runA difference between what was decided and what is in the ERP that no single step would see.After the full run the ERP rows are checked against the log, and the journal is checked for anything still pending or waiting for a person: no problem found. Tests then break a copy of the run, and each case is reported: a changed log row, a log cut at the end, a log rewritten with the key during the run (found against the decisions the run holds in memory), a duplicate, missing or changed ERP row, an ERP row with no decision behind it, and a source hash that differs from receipt. An ERP that refuses every write, or never answers, shows up in the reconciliation report, and its records go to a person queue.Tests: 10 (test_write_path.py)
Reproducible runResults that cannot be repeated and checked.The same seed gives the same data and the same fault plan, the three layers of the score add up, and the decision log carries no clock time, so the same input gives identical bytes. Seed 17, run again with the other seeds, gives the numbers of the main run and is left out of the 39 other runs.Tests: 6 (test_prototype.py 2, test_write_path.py 2, test_ledger.py 1, test_facts.py 1)
The check never reads the answer keyResults that look good only because the check could see the truth.A test reads the source of the check: no reference to the truth files, no file access, and only three standard modules imported.Tests: 4 (test_prototype.py)
Standard library, no networkHidden dependencies or network calls.A test parses every Python file of the prototype and fails on any import from outside the standard library and on any network module.Tests: 1 (test_facts.py)

Test suite on the run that produced these numbers: 269 of 269 pass. Python standard library only, no network modules. The write path does not change the scores: they are the same with and without it. The numbers of the run on this page come from its facts file, which is written only when every test passes, the test log adds up, the decision log verifies with its key and the ERP holds no extra row. Test names and code on request.

7. Limits