Skip to content

Free guide

Give data a type and check it at the door

Use TypeScript to describe allowed states and Python to inspect incoming rows before they reach a report.

Why it matters

A product manager defines which values have meaning. A developer turns those definitions into checks that keep malformed records visible.

Core concepts

Types describe promises

A TypeScript union can name the known states of a task, such as queued, sent and failed. Narrow a value after checking its shape. Types are checked during development, so an external JSON payload can still arrive with an unexpected value.

Validate at a boundary

Treat a file, webhook or API reply as unfamiliar data. Check the required fields, allowed values and units. Keep missing, zero and false distinct. A blank duration and a duration of zero can answer different business questions.

Choose a fitting language

React and TypeScript often serve the interactive UI. Python works well for a small data check because dictionaries, loops and string functions are easy to inspect. SQL works on the whole relation. Choose the place that protects every caller.

Preserve the original meaning

Explicitly map source labels to internal labels. Preserve identifiers with leading zeroes as text. Invalid values need a review path and a reason. Counting rejected records helps reveal a changed source format.

Try it step by step

  1. Write three valid example rows and three invalid ones. Include a legitimate zero.
  2. Agree what each field means, whether it can be blank and who owns the mapping.
  3. Validate before conversion and count accepted and rejected rows separately. Compare their sum with the source count.

Build a field contract with source field, meaning, destination, type, allowed values and reject behavior.

Worked example

Fictional example: A store exports item 0007 with a quantity of zero. Converting both fields to integers loses the item identifier. A review rule that rejects all false-like values also drops the valid quantity.

Python
rows = [{"item": "0007", "qty": 0}, {"item": "0008", "qty": "?"}]
accepted = [r for r in rows if isinstance(r.get("item"), str)
            and r["item"] and type(r.get("qty")) is int and r["qty"] >= 0]
print(accepted[0]["item"], len(accepted), len(rows) - len(accepted))
# 0007 1 1

Common mistake

An agent invents an “unknown” category that quietly sends new rows down the normal route.

Practice exercise

Run the Python snippet. Add a row with quantity True. Predict the rejection before running it. Then add a new valid zero and update the expected totals.

Check your understanding

A supplier introduces a new status. Which behavior best protects a workflow?

  1. Treat it as complete
  2. Drop the record
  3. Hold it with a reason and count it
Show answer

Hold it with a reason and count it. The record stays available for reconciliation while the team learns what the new value means.

Takeaway

Define missing and zero separately before writing a converter.

Further reading

Browse more lessons