Integration and automation ·Build

Why does someone still fix incoming data by hand?

An order-capture demo and a SAF-T import, on synthetic data

Orders, invoices and accounting files arrive from systems you do not control, each in its own format, and someone corrects the wrong ones by hand while errors keep reaching the main system. A wrong record that looks right is worse than one that is rejected. So the rule is: keep the original, check every record against explicit rules, and quarantine what does not fit instead of guessing. In an order-capture demo, 13 of 36 documents were posted with nobody involved, exactly those the rule predicted, and none that needed review was posted; in a SAF-T import, all seven kinds of broken file were quarantined with their reasons. I have built receiving APIs like this in production; the original store and the quarantine are the two parts I would never leave out.

Problem
data arrives from systems you do not control, each in its own shape, and someone fixes the bad records by hand while errors still reach the core system.
Deciding constraint
you cannot change the senders, and a wrong record that looks right is worse than a rejected one.
Choice
keep the original, check every record against explicit rules, map it to one internal shape, and quarantine what does not fit instead of guessing.
Result
in the order-capture demo, 13 of 36 documents were posted with no person involved, exactly those the rule predicted, none that needed review was posted, and the ERP is read back after every posting. In the SAF-T import, seven kinds of bad file were all quarantined with their reasons, the same file twice changed nothing, and 100,000 lines imported in 5.5 s.

If this is your situation

If people correct incoming data by hand every day, the first step is the list of sources with real samples, and a count of the fields they fix most.

Integration and automation → discuss an integration problem

For your technical team How it was diagnosed, the options rejected and why, what went wrong, and the decision record. About 7 min read

Context and scope

Your system receives orders, invoices or accounting files from customers, suppliers and their software. Each sends its own codes for the same product, its own layouts, and optional fields that are sometimes missing and sometimes empty. Two builds show the rules below on synthetic data. The first reads customer orders and supplier invoices that arrive as PDFs, scans and emails, and posts them to an ERP through its published API, here against a mock of it. The second imports SAF-T files, the standard accounting export, into a multi-tenant back office.

In scope: receiving, validating, mapping, posting and reconciling inbound data. Out of scope: outbound feeds, and the senders' own systems. Assumption: you can obtain real samples from each source, not only its documentation, which is usually optimistic.

Drivers

Constraints

  • The senders cannot be changed and may change their format without notice.
  • Meaning differs between sources, not only format.
  • The people who know the products, not only developers, must be able to fix a mapping.

Scenarios

  • When a sender says "we sent it", the original is there, byte for byte. Measured by a hash on every file.
  • When a record does not fit, it is quarantined with its reason, never guessed. Measured by seven kinds of corrupted SAF-T file, each quarantined.
  • When the same file arrives twice, nothing changes the second time. Measured by importing it again, and by the duplicate check on every document.
  • When a new product code appears, a reviewer's correction becomes the mapping for next time, without a deployment. Measured by the learned-alias list.
  • When something posted differs from what was meant, the reconciliation shows it. Measured by reading the ERP back after every posting.

Options against those drivers

  • Accept each format directly into the core

    Fits when
    there are one or two sources that rarely change.
    Breaks when
    every new source changes the core, and bad data enters.
  • Chosen

    One internal shape, a small adapter per source

    Fits when
    there are several sources, growing in number.
    Breaks when
    an adapter per source has to be maintained, and the internal shape is designed carelessly.
  • An integration platform

    Fits when
    there are many sources and a team to run it.
    Breaks when
    it adds another product, licence and skill set to carry.
Option Core stays stable Bad data blocked Cost of a new source Main drawback
Direct into the core No No Change the core Every new source
One shape, adapters Yes Yes, at the adapter One adapter The shape must be designed with care
Integration platform Yes Yes Configuration, plus the platform's skills Licence, another product to run

The decision and how it works

Six rules, in the order a record meets them.

Keep the original first. Every file is hashed and stored untouched; a byte-identical file is recorded as a duplicate of the first and never processed twice. Parse defensively. SAF-T is untrusted XML from someone else's software, so it is read with entity expansion off and a size cap.

Check against explicit rules. For an invoice: the tax number's checksum, a plausible date, quantity times price less discount equals the line total, the lines add up to the net total, VAT per rate, gross equals net plus VAT, and the invoice's QR code agrees with what was read. For a SAF-T file: the taxpayer's checksum and identity, a one-month period, balanced transactions, declared totals, known accounts, unique transaction ids and dates inside the period.

Map without guessing. The customer or supplier is found by tax number, never by name. An order line matches an article by a learned alias, then its code, then its barcode; a fuzzy match on the description is only a candidate for a person. When a reviewer corrects a line, the correction becomes an alias, so the same code maps automatically next time.

Quarantine what does not fit. An order that fails a check, or reads with low confidence, waits in a review queue with the reason beside each value. A SAF-T file that fails any rule is quarantined whole, with its reasons and its bytes kept, and nothing enters the ledger.

Write once, then check. Posting to the ERP is idempotent; after it, the ERP is read back and lines and totals compared, per document and per batch. Importing an identical SAF-T file does nothing; a corrected one replaces that period's lines.

How a source is added, and how it is undone

Add a source in shadow mode first: receive and store its files, run the checks and the mapping, and compare the result with what people key in by hand today, without writing to the core. Switch the source on when the differences are understood. Because the original is kept, undoing it means turning the source off and replaying the stored files once the cause is fixed.

How the decision is kept true

The order-capture demo is measured against a ground-truth manifest of 36 generated documents with deliberate traps:

Measured Result
Values read correctly, PDFs with a text layer (24) 100%
Values read correctly, orders written in an email (5) 99.2%
Values read correctly, scans and photos (7) 95.6%, every one sent to review
Order lines matched to the right article 99.5% (181 of 182)
Posted without review 13 of 36, exactly those the rule predicted
Posted without review when review was required 0

The SAF-T import is measured by files built to fail: seven kinds of corruption, each quarantined with its reason; an identical file imported twice; a corrected file replacing its period; and one 100,000-line file (51 MB) imported in 5.5 s, about 18,000 lines a second.

In production, measure first the fields people correct by hand and who corrects them; that is where the rules are missing. Then the age of the oldest item in the review queue, mapping coverage per source, and a reconciliation in which accepted plus waiting plus rejected equals arrived.

Where it went wrong, and the risks that remain

A file that looked right was not. The first generated SAF-T files carried an ns0: namespace prefix on every element: valid XML, but not what a SAF-T file looks like, and the corruption tests, which worked on the text, missed it until the default namespace was registered. Test against files shaped like the real thing, not only against the parser.

A seed overflowed at scale. A generator expression overflowed a 32-bit integer at 1.5 million transactions; the small test files never reached it. Generate test data at the size you will run.

Risk Likelihood Impact Mitigation Owner
A mapping guesses and fixes data silently High Confident, wrong records Fuzzy matches only as candidates; quarantine, slower and honest Tech lead
The original is lost Medium Every dispute is one word against another Hash and store the file before anything else Developer
Mappings only developers can change High Each new code is a deployment Learned aliases from reviewers' corrections Product owner
No reconciliation Medium Missing or wrong postings found by the customer Read the ERP back after every posting Operations
A source changes format without notice Medium Files start failing the checks Rules per source; alert on the quarantine rate Integration owner
A local subset of a standard passes files the official schema rejects Medium A file accepted here is refused downstream Validate real SAF-T files against the official XSD as well Developer

Operations, cost and scale boundary

  • To run: the review queue and the quarantine, daily.
  • To learn: each source's real behaviour, from samples.
  • Cost: an adapter per source, which is why a platform starts to pay once sources are many. In the demo, reading takes a median of 30 s per text document and 3 to 10 minutes per scan or photo on a laptop GPU, so a scan is never posted automatically.
  • Tested range: 36 generated documents; SAF-T files up to 100,000 lines.
  • Where the choice flips: with a few stable sources the adapters are cheap; with dozens, a platform's licence can cost less than their upkeep.

On a different stack

The six rules do not depend on the language. What differs is how the rules are expressed (a schema, a validator, code) and where the queue lives, in whatever your stack already uses for messaging and storage.

Integration and automation → discuss an integration problem

Where to start?

Describe the problem in a few minutes: what it is about, a little context and how to reach you.