Arman Pouyaei Start a conversation
Lesson 34  ·  Nov 18, 2026
Data Engineering Fundamentals

Data quality gates: fail loud, fail early

Yesterday's practice ended on a problem: cleaning code cannot quietly fix values it never checks. Production pipelines add a gate between silver and gold — a written contract covering columns, types, ranges, and uniqueness — that the data must pass, or the run stops and a human hears about it.

The code

import pandera.pandas as pa
from pandera import Check, Column, DataFrameSchema

observation_schema = DataFrameSchema({
    "station": Column(str),
    "time":    Column("datetime64[ns, UTC]"),
    "temp_c":  Column(float, Check.in_range(-60, 60)),
    "lat":     Column(float, Check.in_range(-90, 90)),
    "lon":     Column(float, Check.in_range(-180, 180)),
}, checks=Check(
    lambda df: not df.duplicated(subset=["station", "time"]).any(),
    error="duplicate station/time rows"))

clean = observation_schema.validate(silver, lazy=True)

In practice

The schema is documentation that executes. Every rule a data consumer assumes — temperature is a float, latitude is on Earth, one row per station per time — is written once, in code, and enforced on every run. When the source changes its format, the gate fails on day one instead of corrupting a month of gold.

lazy=True collects every failure in one report — which column, which check, which rows — instead of dying on the first problem. Data problems get fixed in batches, not one pipeline run per bug.

Gates live at layer boundaries. Validate silver before gold is built from it, so bad data fails one step away from its source. And failing loud beats serving wrong numbers: a stopped pipeline is an incident, but a wrong map is a lie.

Python bridge: This is Python's assert grown up: one declarative object instead of scattered if-statements, working directly on the pandas frames you already build.

Further reading

Lazy Validation — pandera documentation (pandera's own guide to collecting all validation failures in a single pass with lazy=True)

Try it

Practice question: Add two checks to the schema above: wind speed (column wind_kmh) can never be negative, and humidity (humidity_pct) must lie between 0 and 100. Write the two Column lines.

Show answer
"wind_kmh":     Column(float, Check.ge(0)),
"humidity_pct": Column(float, Check.in_range(0, 100)),

Result: Range checks encode physics: most 'impossible data' bugs — negative wind, 140% humidity, a station at latitude 140 — are one Check away from being caught at the gate instead of inside someone's report. Notice both lines slot into the same schema dict; a contract grows one rule at a time, usually right after an incident teaches you the rule.

← All posts