Blog ·

Reading supplier stock CSVs: what goes wrong and how to catch it

CSV is supposed to be the simple format. Seven commas, a newline, twenty years of tooling, and yet every new supplier we onboard finds a fresh way to break our parser. What follows is a catalogue, loosely sorted by how often we see it, of the ways a stock export sabotages an ingest.

Header drift

"SKU" becomes "Sku" becomes "Product Code" becomes "Item No.". The column you mapped last week isn't there this week. The fix is to pick column names per supplier once, make the mapping explicit, and alert when the expected column is missing — don't silently fall back to a best-match heuristic because that's how you end up writing a price value into an on-hand field.

Row 1 isn't the header

Some suppliers ship a three-line preamble: company name, generated timestamp, blank row, then the headers. Excel does this by default if the export was designed for human eyes. Make `headerRow` configurable per supplier. Default to 1 and let merchants override it.

Encoding surprises

The big ones we've seen:

Numbers that aren't numbers

Quantity columns arrive as:

Cast to integer after trimming, removing thousands separators, and flagging ranges. If it still can't be coerced, report the row — don't drop silently.

XLSX is worse, actually

XLSX is CSV's ambitious cousin. Three failure modes we see regularly:

Zero rows is a canary

The most important check in the whole pipeline: if a file came in, parsed without error, and produced zero rows, alert. That almost always means the supplier changed their format and you're now silently missing all their updates. A "succeeded" ingest with zero rows is worse than a failed one, because nobody looks.

Defences that actually work

  1. Explicit per-supplier column mapping. Never auto-infer past the first preview.
  2. Fail loudly on missing columns, unexpected formats, zero rows.
  3. Keep the raw attachment. When a parse fails three weeks later, you need the original bytes to diagnose.
  4. Surface unmatched SKUs as a first-class audit output, not a log line.
  5. Sender allowlist per supplier. Spoofed From headers are the classic "stock suddenly zero" attack.

Stockpost does all of this. See how the pipeline fits together, or install on a 14-day trial.

Related reading: