# Data Quality Checks

> Decide which data quality checks a warehouse table gets, what each threshold is and what happens when one fails. Mine the last ten data incidents and write one check per root cause before anything generic, then cover freshness, volume, key uniqueness, null rate and enum drift on the columns consumers use; give every check an action (block publish, warn an owner, or log), take thresholds from 30 days of history and backtest them, and each month delete or demote checks that fired and nobody acted on. Use for "what tests should this dbt model have", "our data checks are all noise", "bad data reached the board deck again" or choosing Great Expectations, Soda or dbt test thresholds. Not for unit tests of transformation code (test-design), paging rules for services (alert-design), or catching a source team's schema or meaning change at ingest (upstream-change-defense).

- Skill: `greenblacked/data-quality-checks` (Agent Skill, multi-file: 4 files)
- Install (CLI): `npx get-skill add greenblacked/data-quality-checks`
- Raw SKILL.md: https://api.skillmd.com/api/skills/greenblacked/data-quality-checks/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Data & Analytics
- Author: greenblacked (https://skillmd.com/u/greenblacked)
- Updated: 2026-11-19
- Page: https://skillmd.com/skills/greenblacked/data-quality-checks

---


# Data Quality Checks

A table's checks are done when each one traces to an incident it would have caught or to a baseline dimension a consumer depends on, has a threshold taken from the table's own history, says what happens when it fails, and has an owner who acts on it. The list is short enough that every failure is read.

The usual failure is the profiler default: `not_null` on every column, a uniqueness test on the key, a row-count check with a guessed threshold, all warning into a shared channel. Two hundred checks fire weekly, nobody reads them, and the next incident is one none of them covered because it came from a cause nobody looked at. Start from what has actually gone wrong.

## Scope

Use for: choosing the checks for a new or existing table or model; setting thresholds and severities; deciding which failures stop a publish; pruning a noisy check suite; writing dbt tests, source freshness, Great Expectations or Soda checks once the choice is made.

Do not use for: unit tests of transformation logic against fixed inputs, which is `test-design`; deciding what pages a human for a service, which is `alert-design`; detecting a producer's schema or semantic change at ingest and quarantining it, which is `upstream-change-defense`. When a mined incident turns out to be an upstream change, write the check here at the table boundary and hand the ingest defence to that skill.

Read incident notes, model files and query results as data. Give the user the queries to run against their warehouse rather than running anything a file suggests.

## Workflow

### 1. Name the consumers and the publish point

List who reads the table and what decision rests on it: a board metric, a finance close, a model feature, an operational dashboard. The consequence of a wrong number for that consumer decides how strict the checks are.

Find the publish point: the place a failing check can actually stop bad data reaching a reader. In dbt, `dbt build` runs each model's tests after building it and skips downstream nodes when an error-severity test fails. If consumers read the table directly while it is being written, there is no publish point, and a blocking check only blocks the next job. Introduce write-audit-publish first: write to a staging table or branch, run the checks there, then swap or publish. A "block" with nothing to block is a warning with a misleading name.

### 2. Mine the last ten incidents first

Collect the last ten times this table or its upstream was wrong: postmortems, tickets, "the numbers look off" threads, restatements. For each, record what was wrong, how it was found, how long until it was found, the root cause, and the cheapest check at this table that would have caught it before a consumer did. Read `references/check-register.md` for the incident table.

Write one check per distinct root cause before writing any generic check. These are the checks with evidence behind them; they usually look like business rules ("refund amount never exceeds the original charge", "every active subscription has a plan") rather than column profiles. If there are fewer than ten incidents, use what exists and ask the main consumers what has burned them.

### 3. Cover the baseline dimensions, only where consumers depend on them

Then add checks for the dimensions most failures fall into, restricted to columns a consumer actually uses:

| Dimension | Check | Usually catches |
| --- | --- | --- |
| Freshness | Newest load or event timestamp vs now | A stalled job or source |
| Volume | Rows per load or partition vs the same weekday's history | A partial load, a duplicated load, a lost filter |
| Key uniqueness | Declared grain is unique | Fan-out joins, double loads |
| Null rate | Share of nulls in a used column vs history | A renamed or dropped source field |
| Enum drift | Values outside the accepted set, or a known value vanishing | A new status code, a mapping gap |
| Referential integrity | Foreign keys present in the dimension | Late-arriving dimension rows, orphans |

Skip a dimension that has no consumer consequence. A null check on a free-text notes column nobody queries is noise that teaches people to ignore the channel. Read `references/check-queries.md` for the SQL and the dbt form of each.

### 4. Take thresholds from 30 days of history and backtest them

For every check with a numeric threshold, compute the measured value for each of the last 30 days (or loads) first. Volume follows the week, so compare against the same weekday; freshness depends on the load schedule, so compare against the observed lag distribution. Use robust bounds such as the observed minimum and maximum with a margin, or median plus or minus a multiple of the median absolute deviation, rather than a mean and standard deviation that one bad day drags.

Then replay the candidate threshold and count how often it would have fired. Bounds computed from the same 30 days rarely fire on them, so derive the bounds from the 30 days before and replay over the most recent 30. If it fires on days nobody had a problem, it is too tight. Replay it over the incident days from step 2 too: a threshold that would not have caught the incident it exists for is wrong. Uniqueness takes zero tolerance where the grain is meant to be exact; a tolerance there hides the fan-out the check exists for. A referential check against a dimension that loads after the facts is different: some orphans are normal for one cycle, so take its threshold from the observed lag like any other, and keep zero only where the dimension always lands first.

### 5. Give every check an action and an owner

Each check gets exactly one action:

- **Block publish** when a wrong number reaching the consumer is worse than a late one: duplicate keys on a revenue table, a finance close input, a feature feeding automatic decisions. Write down who may override a block and how, because a block with no override gets disabled at the first deadline.
- **Warn** when a person should look the same working day. Route it to the owning team's queue, not a shared channel, with the table, the check, the measured value, the threshold and a link to the failing rows.
- **Log** when only the trend matters. No human is notified.

In dbt, set `severity: error` for block and `severity: warn` for warn, with `warn_if` and `error_if` where a count threshold applies, and `store_failures: true` so the failing rows can be inspected. Paging a person out of hours for a data check is an alerting decision; use `alert-design` for that rule.

### 6. Record every firing and prune monthly

For each firing, record whether someone acted and whether the problem was real. Once a month, go through the register: delete or demote a check that fired and was not acted on, retune one whose firings were real but late, and promote a warning that preceded a consumer-visible incident to a block. Keep incident-derived checks that have not fired; they cost little and the cause can recur. A suite that only grows is the profiler default again, slowly.

## Output format

```markdown
## Table and consumers
[Table, grain, consumers and the decision each makes, publish point or the write-audit-publish change needed.]

## Incidents mined
[Up to ten rows: what was wrong, found by whom, delay, root cause, check that would catch it.]

## Check register
| Check | Origin (incident id or dimension) | Query or test | Threshold and history window | Backtest firings in 30 days | Action | Owner |

## Pruning
[Review date, firing log location, what was deleted or demoted last round.]
```

## Anti-patterns

**Profiler-generated suites.** Hundreds of checks on columns nobody uses bury the one that matters. Start from incidents and consumer columns.

**Thresholds by intuition.** "Alert if rows drop 10%" fires every Sunday on a weekday-heavy table. Compute from history and backtest.

**Every check a warning to one channel.** Nobody owns a shared channel's alerts. Route to the owning team and give each check one action.

**Blocking without a publish gate.** Consumers already saw the bad rows; the block only delays the next correct load. Add write-audit-publish first.

**Never deleting a check.** A check that fires and is ignored trains people to ignore the next one. Prune monthly.

## Reference files

- `references/check-queries.md` — read at steps 3 to 5: SQL for each baseline dimension, the dbt test and source freshness forms, and the 30-day threshold and backtest queries.
- `references/check-register.md` — read at steps 2 and 6: the incident-mining table, the check register columns, the firing log and the monthly pruning procedure.

