Skip to content

Lesson 6 of 9 · 24m

Data Quality Checks That Actually Matter

Validate completeness, uniqueness, validity, freshness, and distribution at pipeline boundaries instead of collecting decorative test failures.

Most data quality programs begin with enthusiasm and end with a dashboard full of red tests nobody trusts. The problem is usually not the framework. It is that teams test what is easy rather than what protects a decision. A null-rate check is useful if null customer IDs break billing. It is noise if the field is decorative metadata. Quality gates belong at boundaries where bad data becomes expensive.

The useful dimensions

Test completeness, uniqueness, validity, freshness, and distribution — but tie each check to a consequence and a response.

completeness    did expected rows, partitions, or files arrive?
uniqueness      are keys duplicated where identity must be singular?
validity        do values conform to types, ranges, and controlled vocabularies?
freshness       is the data new enough for its consumer?
distribution    did volume or meaning shift in a way humans should inspect?

These are diagnostic categories, not a checklist to apply blindly to every table.

Validate before publication

A quality gate that runs after users consume the data is monitoring, not prevention.

SELECT order_id, count(*) AS copies
FROM staging.orders
WHERE dt = DATE '2026-03-14'
GROUP BY order_id
HAVING count(*) > 1;

If duplicates appear, stop publication. Keep the previous good partition visible rather than exposing corrupt new data.

dbt tests can encode invariants close to the model:

models:
  - name: orders
    columns:
      - name: order_id
        tests: [unique, not_null]
      - name: amount_cents
        tests:
          - dbt_utils.accepted_range: {min_value: 0, max_value: 100000000}

That is valuable, but a valid amount can still be economically impossible and a unique key can still refer to the wrong customer. Quality requires domain knowledge.

Distribution shifts and quarantine

Exact constraints miss many real incidents. Compare today's output with expected history:

def volume_guard(row_count, baseline):
    ratio = row_count / max(baseline, 1)
    if ratio < 0.5 or ratio > 2.0:
        raise DataQualityError("row count outside expected range")

Rejecting malformed rows outright can destroy evidence and create invisible gaps. Quarantine them with reason codes, then decide whether the pipeline can proceed with a reduced complete dataset or must halt because completeness is essential.

Field notes

  • Every alert needs an owner and a runbook. A test without a response is a decorative anxiety generator.
  • Do not enforce uniqueness on event data unless the event contract actually promises uniqueness.
  • Validate row counts per partition, but beware seasonal patterns and product launches. Static thresholds age badly.
  • Include reconciliation counts between source and target when money, inventory, or compliance depends on exact completeness.

Was this lesson helpful?

Sign in to rate