Data quality · 3 min read · Nov 2026
Quarantine, don't delete: handling bad rows in a healthcare lakehouse
Pawan Yandapalli · Data engineer
In health data, a bad row is rarely garbage. It's usually a real claim with one wrong field: a missing member ID, a negative amount, a service date in the future. Dropping it silently loses money or care history. Letting it through corrupts every report built on top of it.
The pattern I use is to hold it, explain it, and replay it.
Bronze keeps everything, exactly as it arrived
Every record lands in Bronze unchanged, with where it came from and when it was loaded. Bronze is the system of record for "what did the source actually send us?", which is what makes everything below safe to re-run.
Silver splits each batch into passed and quarantined rows
Rules live in configuration next to each source, not scattered through code. From my public rebuild on synthetic Synthea data:
expectations:
- {name: claim_id_present, rule: "claim_id IS NOT NULL"}
- {name: patient_linked, rule: "patient_id IS NOT NULL"}
- {name: service_date_present, rule: "service_ts IS NOT NULL"}
- {name: outstanding_not_negative, rule: "outstanding IS NULL OR outstanding >= 0"}Silver evaluates every rule on every row and records which ones failed:
def apply_expectations(df: DataFrame, source: Source) -> Tuple[DataFrame, DataFrame]:
"""Split rows into (passed, quarantined). Quarantined rows list the checks they failed."""
checks = [F.when(~F.coalesce(F.expr(e["rule"]), F.lit(False)), F.lit(e["name"])) for e in source.expectations]
failed_list = F.filter(F.array(*checks), lambda x: x.isNotNull()) if checks else F.array().cast("array<string>")
flagged = df.withColumn("_failed_checks", failed_list)
passed = flagged.where(F.size("_failed_checks") == 0).drop("_failed_checks")
failed = flagged.where(F.size("_failed_checks") > 0)
return passed, failedTwo details matter. A rule that evaluates to NULL counts as a failure, not a pass. And a quarantined row carries the names of the checks it failed, so whoever fixes the source knows exactly what to fix.
Replays have to be safe
Once the source is fixed, the row is replayed from Bronze. That only works if running the same data twice can't create duplicates, so Silver keeps the latest version of each business key:
def latest_per_key(df: DataFrame, key) -> DataFrame:
"""Keep the most recently ingested row per business key, so replays are safe."""
w = Window.partitionBy(*key).orderBy(F.col("_ingested_at").desc(), F.col("_batch_id").desc())
return df.withColumn("_rn", F.row_number().over(w)).where("_rn = 1").drop("_rn")Alert on the rate, not the row
A handful of quarantined rows is normal. A sudden jump means something upstream changed. Alerting on the failure rate per source catches a broken feed quickly without paging anyone for routine noise.
Why it's worth the extra design work
- Gold and every report on it only ever see rows that passed.
- No row is lost: everything is either in Silver or in quarantine with a reason.
- Fixing a source is a replay, not a manual backfill.
Code from github.com/pawanyandapalli7/data-engineer-portfolio (projects/azure-lakehouse), built on synthetic data.