
We seeded twelve deliberate defects into a four-order test batch and ran our data quality rules against each one. The rules that look at one row at a time caught seven. Adding checks across rows and tables raised that to ten. When we also compared the batch's count and total with an independent source manifest, we caught all twelve. The five that got past the simple rules included the expensive kind: a duplicate order, a lost order, and doubled amounts that still added up line by line.
That was one local run on SQLite, and nothing in it ran on Databricks. One run like that shows the method, not how well any rules cover production data. Still, for a business that reports from Databricks, it shows the gap a passing suite hides. Checks that pass every day prove only that they found nothing wrong in the records they were given. Feed them records with known faults and you see what they'd miss, which mistakes could reach a revenue report, and which check closes each gap before finance finds it in a number.
We kept the results in a table called a kill matrix, one row per injected defect and one column per set of rules. It's the step after writing data quality checks in Databricks.
The test contract and fixture
"Killed" means detected. The idea comes from mutation testing, except the data changes and the checks stay fixed, and each run injects one defect into a clean fixture. Our fixture is four synthetic orders and two customers, with money in integer cents, under this contract:
- Order and customer IDs are required; order IDs are unique and customers must exist.
- Amounts are positive and at most 100,000 cents. Status is
PAIDorPENDING. - Quantity and unit price are positive; line amount equals quantity × unit price.
- The complete batch contains four orders totaling 100,000 cents, as specified by an independent source manifest.
Reset to the clean fixture before each defect. For example, duplicate an existing ID without adding a row, or remove one order.
Keep valid controls: the baseline plus allowed changes to status, customer, and quantity/price. A suite that rejects everything would catch every defect and be useless.
The kill matrix and its results
We compared three cumulative suites:
- Row rules: required order and customer IDs, amount bounds, and allowed status.
- + Relations/math: all row rules, plus unique order IDs, existing customers, positive quantity and unit price, and matching line arithmetic.
- + Batch checks: all preceding checks, plus reconciliation against the manifest's order count and total.

In a local SQLite 3.51.3 run on this fixture, the suites' predicates detected 7/12, 10/12, and 12/12 defects. All four valid controls passed every suite. Databricks execution and Lakeflow actions need runs of their own, and none of this tells you how well the rules cover defects in production.
The survivors explain what each layer adds. Row rules miss duplicate IDs, unknown customers, and incorrect line arithmetic; the second suite catches all three. A missing order and doubled quantities and amounts survive until batch reconciliation. In the latter case, every line still balances, but the batch total exceeds the manifest.
Keep the source manifest independent: calculating the expected total from the corrupted target defeats the check. Compare the same batch or snapshot, accounting for legitimate filtering or aggregation.
NULL handling in invalid-row checks
Hand-written invalid-row queries deserve their own defect cases. This query fails to identify a missing amount:
SELECT * FROM orders
WHERE NOT (amount_cents > 0);
For NULL, the comparison and its negation are unknown. A WHERE clause keeps only true conditions. Write the invalid condition explicitly:
SELECT * FROM orders
WHERE amount_cents IS NULL OR amount_cents <= 0;
The local probe finds zero violations with the first condition and one with the second, consistent with Spark SQL NULL semantics. This tests a custom invalid-row query, not a Lakeflow action.
For a Lakeflow dataset, express the complete valid condition in its definition:
CONSTRAINT valid_amount EXPECT (
amount_cents IS NOT NULL
AND amount_cents > 0
AND amount_cents <= 100000
) ON VIOLATION FAIL UPDATE
This fragment belongs inside a dataset definition. Keep zero and NULL as separate cases so each boundary has a clear result.
Detection and the warn, drop and fail actions
Run each defect through the actual transformation path in a test environment. Confirm it reaches the intended check. If something upstream removes it first, that check goes untested.
The observable result depends on the expectation policy. Capture this evidence for each one:
warn: the invalid row remains and the named expectation records a violation.drop: the invalid row disappears, the valid control remains, and drop metrics agree.fail: the intended flow reports an expectation violation; a permission or source error does not count.
The pipeline UI shows expectation tracking metrics for warn and drop. A fail expectation fails the update when it detects an invalid record, so its metrics are not recorded. In a triggered pipeline, other parallel flows can continue. See the expectation documentation.
For uniqueness, references and totals, compute joins or aggregates in a validation dataset. An expectation constraint cannot contain a subquery that references another table. To block publication, use separate validation and publication pipelines with an explicit success dependency between their tasks. A validation table alone does not provide that gate. See validation tables and pipeline control flow.
Recording and rerunning the matrix

Save the fixture, defect ID, rule version, expected failure and observed result. Separate execution errors and cases that never reached the check from detected and missed defects.
Check the intended rule as well as the suite. The one-cent arithmetic defect also breaks the batch total; reconciliation alone could conceal a broken arithmetic check.
Rerun when predicates, transformations or actions change. Require every designated critical defect to be detected and every valid control to pass. Review each survivor before accepting it.
Start with failures that would change a business decision: a duplicate order, an unknown customer, a lost record, an inflated total. Add defects for your own data contract. Before a rule ships, commit the data that must break it.
The matrix decides which rules a release gate for Databricks data should block on, and it sits beside the freshness, volume and schema checks in how we run data engineering on Databricks. Which defects count as critical is a governance decision as much as an engineering one, because it's the report's owner who knows what a wrong number costs.
Frequently asked questions
Does a clean kill matrix mean my data quality rules are complete?
No. The matrix only covers the defects you chose to inject, so it says nothing about defects you never thought of. Our run used one fixture of four orders, and it measured which checks detect which injected defects. To learn how your rules do against production data, add a defect to the matrix each time a bad record gets past them.
Can I run the same matrix against a Lakeflow pipeline instead of SQLite?
Yes, but it needs its own run, because the SQLite results don't carry over to Databricks execution or to the warn, drop and fail actions. Send each defect through the real transformation path in a test environment. Then check what each action should leave behind: the row stays with a recorded violation for warn, the row disappears for drop, and the update fails for fail. Keep execution errors, such as a permission problem, apart from defects that were caught.
Can the kill matrix run in CI?
Yes, and that's where it pays back. Each defect is a small fixture, so the whole matrix runs as ordinary test cases on every change to a rule, and the build fails when a defect marked critical survives or a valid control is rejected. The runner has to pass pytest's result on to CI, which is the gap our notebook CI post covers.
How much work is a kill matrix to keep up?
Most of the work is the first version: one clean fixture and one defect per rule in the data contract. After that, a new rule arrives with the defect that should break it, and a bad record found in production becomes one more row. A defect a team decides to accept stays in the matrix as a recorded survivor, so the decision is visible the next time someone reads it.