Before a customer’s data can flow into your system, it has to be mapped: each of their columns pointed at one of your canonical fields, and each value coerced to a type. Their age_txt becomes your age: int; their status becomes your active: bool. Get the mapping right and the clean rows validate while the genuinely bad ones are quarantined — held aside, not silently dropped. Get it wrong — point age at the name column — and everything fails at once. Pick the mapping for each field and watch validation light up, row by row. This is the boundary discipline from the integration handbook, and the CSV mapper challenge, made visual.
map each column to a field · coerce to a type · quarantine bad rows (don’t drop) · wrong mapping fails everything
canonical schema
The clean, typed shape your system expects — the target every customer export must be mapped onto.
coercion
Converting a raw string value to a type: "34" → 34 (int), "true" → true (bool). It fails on bad values.
quarantine
Setting aside rows that don’t coerce, for inspection — instead of silently dropping them and losing data.
mapping
The choice of which customer column feeds each canonical field. The one decision that makes or breaks the import.
mapping.js — coerce at the boundary
Fix the mapping
Three canonical fields need a source column. The starting mapping is wrong — watch every row fail. Click each field to cycle which customer column feeds it. When the mapping is right, the clean rows go green and only the genuinely bad values are quarantined.
0
rows valid
4
quarantined
✗
mapping
How it works
The lab is a tiny mapping-and-validation engine, and building it teaches why mapping is the highest-leverage — and most dangerous — step of a data import. A canonical schema names the fields you want and their types. A mapping assigns each field a source column from the customer’s export. Validation then walks every row and tries to coerce the mapped value to the field’s type: a string like "34" becomes the integer 34, "true" becomes the boolean true, and anything that can’t convert — "N/A" as an int, "yes" as a strict bool — raises an error. A row is valid only if all of its fields coerce; otherwise the whole row is quarantined, set aside for a human to inspect rather than silently dropped, because silently dropping rows is how an import corrupts a dataset without anyone noticing. Two lessons fall out immediately. First, a wrong mapping is catastrophic and total: point the integer age field at the name column and every single row fails coercion at once — the failure isn’t subtle, which is actually a gift, because it’s obvious. Second, even a correct mapping doesn’t make every row valid: some values are genuinely bad (a missing age, a status of "yes" where you expected true/false), and the right behavior is to quarantine exactly those rows and let the good ones through. That distinction — a broken mapping versus a few broken rows — is the one an FDE has to read at a glance, because the fixes are completely different: re-map the field, versus hand the quarantine list back to the customer.
1
A schema wants typed fields
Your system expects age as an int, name as a string, active as a bool. The customer’s export has differently-named columns of raw strings.
2
Mapping assigns a source column
Each canonical field is pointed at one of the customer’s columns. This single choice determines whether the import works at all.
3
Coercion validates row by row
Each mapped value is coerced to its field’s type. A row is valid only if all its fields coerce; otherwise it’s quarantined for inspection — never silently dropped.
✓
Read broken-mapping vs broken-rows
A wrong mapping fails every row at once (re-map the field). A correct mapping still quarantines the genuinely bad values (hand them back to the customer). Different symptoms, different fixes.
Wrong mapping
all rows fail
Right mapping
bad rows quarantined
Never
silently drop rows
Coerce at
the boundary
The code
# Map + coerce a customer export onto a canonical schema
schema = {"age": "int", "name": "str", "active": "bool"}
mapping = {"age": "age_txt", "name": "name", "active": "status"} # the key decisionfor row in customer_rows:
try:
clean = {f: coerce(row[mapping[f]], t) for f, t in schema.items()}
valid.append(clean)
except BadValue:
quarantine.append(row) # set aside — do NOT drop silently# wrong mapping → every row raises. a few bad values → a few quarantined.
The picture: columns, mapping, coercion, two exits
The lab’s own four rows under the correct mapping. Each field is checked separately, and one failed field sends the whole row to quarantine with its reason. A row is never dropped. The unused joined column is where the lab’s starting mapping goes wrong: active pointed at it fails on every row, because no date is a boolean.
Worked example: the same four rows under five mappings
The rule from the page is that a wrong mapping fails every row, while a right one quarantines only the bad rows. That holds for typed fields. Running the lab’s coerce() under each mapping shows where it stops holding:
Mapping
Ada
Bo
Cy
Di
Valid / quarantined
Correct: age ← age_txt, name ← name, active ← status
valid
“N/A” not int
“yes” not bool
valid
2 / 2
age ← name
“Ada” not int
fail
fail
fail
0 / 4
active ← joined
“2021-05” not bool
fail
fail
fail
0 / 4
name ← age_txt (others correct)
valid, name “34”
quarantined
quarantined
valid, name “41”
2 / 2
name ← joined (others correct)
valid, name “2021-05”
quarantined
quarantined
valid, name “2022-03”
2 / 2
Rows 4 and 5 are the dangerous ones. A str field accepts any value, so pointing name at the wrong column produces exactly the same 2 / 2 count as the correct mapping. The only difference is that Ada is now called “34”. Validation catches type errors, not meaning errors. Before you sign off on a mapping, look at a few output rows with your own eyes, or add value checks to the string fields (a name that is all digits, say). You can try it in the lab: point name at age_txt and watch the counts stay the same.
Trade-offs: what to do with a row that fails
Validation itself is cheap: one pass, rows × fields coercions, which is 4 × 3 = 12 in the lab. The real decision is the failure policy. In this table, read the columns as policy, what loads, what you risk, when to use it.
Case
Time
Space
Why
Reject the whole file on the first error
nothing
one bad row blocks every good row
Ledgers and billing, where a partial load is worse than none.
Quarantine the bad rows (the lab)
the good rows, now
someone must work the queue
The default for most imports. Store the row, the field, the raw value and the reason.
Coerce failures to a default (“N/A” → 0)
every row
fake values that look real
Almost never. A zero age quietly drags every average down.
Drop failures silently
every row that parsed
lost rows, no record of them
Never. The import reports success and the totals are wrong.
Widen the parser (“yes” → true)
more rows
reading values the customer did not mean
Only for spellings agreed with the customer and written down in the mapping.
The quarantine count is also a health signal. The same count from one load to the next is ordinary dirty data. A sudden jump, or every failure landing on one field, points to the mapping or a changed export.
Common mistakes
Reading a clean run as a correct mapping
As the table above shows, a string field never fails coercion. A wrong mapping into name loads without a single error. Check a few output rows by eye, and add value rules to free-text fields.
Turning identifiers into numbers
A ZIP code like "02134" coerced to an int becomes 2134, and account numbers lose their leading zeros the same way. If you never do arithmetic on a value, it is a string, however numeric it looks.
Guessing date formats
"03/04/2022" is 3 April in the UK and March 4 in the US. Agree the format per source and parse it strictly. The lab’s joined values like "2021-05" carry only a month, so do not invent a day.
Forgetting whitespace and the byte-order mark
The lab’s int check is ^-?\d+$, so " 34" fails. Spreadsheet exports often add trailing spaces, and a UTF-8 byte-order mark glued to the first header stops age_txt matching the mapping. Trim values and strip the mark before you map.
Quarantining without a reason
A quarantine that holds only the raw row turns into a pile nobody can work through. Record the row number, the field, the raw value and the rule it failed, as in “row 3: active = “yes”, not a bool”. The customer can fix that in their source.
Where this shows up in production and interviews
The first week of an FDE engagement
The customer’s first export almost never matches the docs. Mapping it, running the validation, and sending back a quarantine report with reasons is often the first real thing you deliver, and it shows the customer their own data quality.
Validation libraries and dead-letter queues
Schema libraries such as pydantic or JSON Schema validators do the coerce-and-check step in code. In streaming pipelines, quarantine is called a dead-letter queue: Kafka Connect, for example, can route records that fail conversion to a separate topic instead of stopping.
Mapping as configuration
Keep each customer’s mapping as versioned data rather than code. Then the second customer is a new mapping file, not a new branch, and a renamed column is a one-line change you can review. An auto-mapper that guesses from header names should only suggest: as the worked example shows, a wrong guess into a string field passes validation.
The interview version
“A customer’s CSV import: half the rows fail. What do you do?” Group the failures by field first. If one field fails on nearly every row, the mapping or the export format changed. If failures are scattered across fields, the data is dirty: quarantine those rows with reasons and send them back.
Quick check
1. You import a customer export and every single row fails validation. What’s the most likely cause?
When all rows fail at once, the problem is almost never the data — it’s the mapping. A typed field pointed at the wrong column (an int field at the name column) fails coercion on every row. The fix is to re-map, not to clean the data.
2. With a correct mapping, a few rows still fail. What should you do with them?
Some values are genuinely bad (a missing age, an unexpected status). The right behavior is to quarantine those specific rows — set them aside, surface them — not to drop them silently (which loses data invisibly) or force garbage through (which corrupts your dataset).
3. Why coerce and validate data at the boundary of your system?
Validating at the boundary means a malformed value is rejected or quarantined at the point of entry, before it flows into your database, models, or reports. Let it in unchecked and a single bad row can silently corrupt everything that trusts the data downstream.
FAQ
What is data mapping in an integration?
Matching a source system’s fields to your target’s fields, including converting values to the right types. A customer export might have "age_txt" holding "34"; your system wants "age" holding the integer 34. Mapping decides which source column feeds each target field, and coercion converts the value — the critical step that lets messy data flow into a clean, typed system.
What should you do with rows that fail validation?
Quarantine them — set them aside for inspection — not silently drop them or force them through with defaults. Silent dropping loses data invisibly; forcing garbage corrupts the dataset. Quarantining makes bad rows visible: count them, show the customer which records failed and why, and fix the source or mapping. A good quarantine report often builds the customer’s trust in the import.
Why does a wrong mapping fail every row?
Because a mapping error is structural, not per-row: point an integer field at a names column and every value is a name, so every coercion to int fails — all rows at once. That’s useful — total failure obviously signals a wrong mapping, versus a few scattered failures signaling genuinely bad data. Reading "all failed → fix the mapping" versus "some failed → quarantine and inspect" is a core skill.
What is schema drift and how do you handle it?
Schema drift is when a customer’s data shape changes over time — a renamed column, a new field, a format change — silently breaking a working integration. Handle it by validating at the boundary (drift shows up as a spike in quarantined rows, not silent corruption), alerting when the quarantine rate jumps, and keeping the mapping easy to update. Never assume this week’s file matches last week’s; validation and quarantine catch drift before it does damage.