Data quality

How to detect schema drift in CSV exports

Detect CSV schema drift by comparing each new delivery with an agreed set of columns, types and required fields. Add checks for changes in what those fields mean, such as a new unit or a different code list. A file can open normally and still produce the wrong result downstream.

The header stayed the same

A distributor sends a weekly file with a column called quantity. For months it contains item counts. After an export update, it contains carton counts. The header still matches, every value is a whole number, and the report completes. If the report still treats each quantity as an item count, it will understate the number of items for products packed several to a carton.

A header check will miss that change. A short source specification, a unit field, or a comparison against a known shipment gives you a way to catch it. For an important field like quantity, write down what is counted and ask the sender to confirm any planned changes.

Decide which changes your process can accept

Write down the columns your report, import or join actually needs. Include what kind of value belongs in each one and which blanks are allowed. Use this as the reference for incoming files.

An extra notes column can be harmless if your workflow reads columns by name and ignores extras. A renamed product key can break a lookup. A reordered header matters if a downstream import reads columns by position. Give each check a response that matches how the file will be used. A warning can be enough for an unexpected optional field. A missing required key should stop a workflow that cannot produce a reliable result without it.

Check each delivery before combining files

Appending multiple exports first makes changes harder to trace. Check each one on arrival and keep its filename or delivery date with the results. For a large batch, a few sample rows help you see the layout, but run required column and value checks across the full delivery where possible. An invalid code near the end of a file can survive a clean preview.

Pay attention to sudden changes in distributions. If an export normally has a mix of shipment statuses and this week every row says pending, compare it with the source. A distribution change can reflect real activity, so use it as a prompt to investigate.

Keep one example of each approved change

When the sender confirms a new format, save a representative file or a small fixture with invented values. Record the date the change takes effect and what should happen if an old-format file still arrives. That gives the next person something concrete to check before changing the import.