# Data quality scorecard

A dashboard looks the same whether the data behind it arrived complete or half empty. This study builds a
quality scorecard for a daily trip feed (a short list of automatic checks that turns every load into one trust
score out of 100), then breaks a month of public Chicago trip data on purpose to see what the checks catch.

Twelve versions of the data were run: one left clean, four faults the checks were designed for plus all four
together, and six new faults written down before anything ran. Version 1 of the checks missed four of the
six new faults. Version 2 adds two checks and tightens one bound; all three changes were written down and
committed before they ran, and version 1 was re-run alongside and came out identical.

Open `index.html` in a browser for the full study: what each fault tripped, why version 1 missed what it
missed, what version 2 changed, which kind of check to use when, and where a trust score fits when people ask
an AI assistant for a number.

## Results

| Scenario | Kind | Trust, v1 | Trust, v2 | Failed checks, v1 | Failed checks, v2 |
|---|---|---:|---:|---:|---:|
| clean | control | 100/100 | 100/100 | 0 | 0 |
| late_partition | built for | 40/100 | 40/100 | 1 | 1 |
| null_spike | built for | 40/100 | 40/100 | 2 | 2 |
| duplicate_load | built for | 40/100 | 40/100 | 2 | 3 |
| unit_change | built for | 40/100 | 40/100 | 1 | 1 |
| combined | built for | 0/100 | 0/100 | 6 | 7 |
| null_dose_2 | new | 100/100 | 100/100 | 0 | 0 |
| null_dose_5 | new | 100/100 | 90/100 | 0 | 1 |
| null_dose_10 | new | 40/100 | 40/100 | 2 | 2 |
| null_spike_other_day | new | 40/100 | 40/100 | 2 | 2 |
| fresh_id_duplicates | new | 100/100 | 40/100 | 0 | 1 |
| partial_late_partition | new | 100/100 | 40/100 | 0 | 1 |

Version 1 caught 4 of 4 built-for faults and 2 of 6 new faults. Version 2 caught 4 of 4 and 5 of 6, failed 0 checks on the clean data and flagged 0 of 17 clean days as anomalous. A held-out set of 8 faults, written by an independent author who never saw the checks and declared before the faults existed, was then scored without changing any check: version 2 caught 2 of 8 (`heldout/results.json`; `python -B -m quality.heldout` re-runs the round only in the full project, because the blind fault files are not in the download). A second round, also declared in advance, added five version 3 rules for those misses (`quality/v3.py`, thresholds from the clean month) and then scored eight new blind faults from an independent author: version 2 caught 2 and version 3 caught 5, with no false alarm on the clean month (`blind2/results.json`; `python -B -m quality.blind2`, likewise only in the full project; the saved results can be checked from the download, the rounds cannot be re-run from it). Of the 5, 2 tripped checks version 1 already had and 3 tripped version 3 rules that had each caught a first-round fault; that grouping follows which check caught each fault, read after the results. The other 3 (area codes shifted by one, durations capped, a missing fare written as zero) were missed by every version. Only 2 of the 5 catches are on fields from the public data; the other 3 read the synthetic arrival times or the synthetic metres column. Version 3's day-copy SQL divides matching pairs by joined pairs, which can only overstate the declared share of matching rows; a recount after the results finds no outcome changes (`day_copy_recount/results.json`; `python -B -m quality.day_copy_recount --check`). The predictions declared before each blind round, and whether they held, are in `predictions/results.json` (computed after the results; `python -B -m quality.predictions --check`).

Version 2's 5 of 6 is a self-test, because its three changes were written for those six faults. The zero false alarms on the clean month count every check, but 14 of the 22 version 2 checks never failed on any fault in this study, and two of them (`daily_reconciliation`, `row_identity`) are bookkeeping: they compare row counts between tables built from the same rows, so they cannot fail. In the AI test (`gate/results.json`), the score cut confidently wrong answers on a faulty table from 14 to 3 of 45 (15 questions asked 3 times), all of the 11 avoided from faults the checks were built or fixed for, and it refused 123 of the 171 answers that would have been right.

Version 2 still misses a 2-point rise in missing fares (6 of 300 fares on January 31; no clean day had more than 3):
it lands just under a bound set by the 0.02 floor, a declared judgement about 8 to 10 times the clean month's
day-to-day standard deviation (`floor_noise/results.json`, computed after the results; `python -B -m quality.floor_noise --check`). Catching the 5-point rise only through the anomaly group drops trust to 90,
not 40, because an unusual day should alert the feed's owner rather than switch the dashboard off.

## Pipeline recovery

The next part loads the same month through bronze, silver and gold Delta tables (the open-source deltalake package
with DuckDB, no Spark) and tests faults in the pipeline itself: late data, schema changes, backfills, replays and
restores. Six layer checks compare the tables and the load history: control totals, watermark and restatement, schema
contract, idempotency, backfill scope, and a rebuild of the published table from the landing table. On 10 faults
written blind by an independent author who never saw the checks, the layer checks caught 3 and the day-level checks (version 3) caught 4, with
no fault caught by both. One generic recovery runbook (rebuild from the landing table, restate) restored 0 of the
2 damaged faults it ran on and made 1 healthy result worse. No check fired on four clean loads batched different
ways. On 8 faults written with the checks in view, the layer checks caught 8, and a recovery written for each fault
put back all 6 that had changed the published numbers, a self-test. Open `pipeline-recovery.html`; the results are on that page.

## Pipeline cost

The part after that runs six layouts of the same pipeline on the same month and measures what each costs to run and to
query: a full rebuild every run, a 3-day incremental window, a merge on the trip ID, a merge that adds each file's totals
to the published table, and the merge unpartitioned or compacted. Over the month of daily files a full rebuild used 2.0 to
2.3 times the transform CPU of the incremental layouts (1.9 to 3.0 in five paired runs against the 3-day window) and read
5.4 times the data of the 3-day window, close to what counting the files each layout opens predicts. The window published
the same numbers as the full rebuild on five declared faults, as its design implies; it never applies late or backfilled
rows once their day has left the window. Adding file totals double-counted a replay and a backfill, and the merge layouts
left the cleaned table two days short after a bad restore. A daily per-day count check flagged the same days as the full
comparison for about a third of its CPU (measured after the results). The ratios are the result: one month of 10,000 trips
on one shared machine, where fixed per-run costs dominate. Open `pipeline-cost.html`; the design is `DESIGN-cost.md`, the
summary `pipeline_cost/results.json`, every job record `pipeline_cost/jobs.json`, and the two measurements added after
the results `pipeline_cost/checks-after-results.json`.

## Lineage and SLOs

The part after that follows an upstream change down to the dashboards. Three synthetic dashboards with ten tiles sit on
the scorecard's own dbt models and semantic layer. Twenty declared changes, 15 breaking and 5 harmless, each ran alone
through a day-by-day replay of the month, and four setups were scored on the same replays: no lineage, lineage impact
analysis before each deploy, lineage plus service levels on the published tables, and those plus a pre-deploy gate with
rollback. Summed over the changes, viewers saw a wrong number on 48 days with no lineage, 46 with the impact analysis, 17
with service levels and 0 with the gate, in the base case (30 to 100, 28 to 93, 17 to 43 and 0 across the declared
sensitivity grid). One author wrote the dashboards, the changes, the service levels and the gate, so these counts are a
self-test. Column lineage with row dependencies named 135 of the 152 assets the breaking changes broke, and 42 that did
not break; the gate blocked 2 of the 4 harmless code changes. The frozen design says "Development runs that only
check the code come first" and "The development runs only showed where the protocol left a step open"; both are
inaccurate and stay because the file is frozen: two development runs computed every outcome, the first already produced
every number reported here, and the readings committed with the code after the second run changed only whether the two
renames' breaches count as late. Open `lineage-slo.html`; the design is `DESIGN-lineage.md`, the
frozen protocol `lineage_slo/protocol.json`, the results `lineage_slo/results.json`, and the tile errors quoted in the
page's prose, computed after the results, `lineage_slo/figures-after-results.json`.

## Alerts and on-call

The last part runs the checks every morning of the month at 06:00, one fault at a time, over 30 faults: the
scorecard's built-for, new and second blind faults plus four lineage changes. Each check has a synthetic owner
(ingestion, analytics or the feed) and a severity, and four routing rules decide who hears and when: page on every
failed check, page only on checks attached to critical models, route by severity, or a daily digest only. A page is
read at 06:30, a ticket at 10:00 on a weekday and the digest at 09:30 the next weekday; dashboard views happen at
09:00. Paging on every failed check let 5 of the 27 faults that changed a dashboard tile reach a viewer before an
owner was told, exactly the 5 no check caught, and sent 320 pages over the month with no fix. Routing by severity let
13 through and sent 155. No rule paged on the clean month. Three ways to treat a failing load were also replayed:
load anyway, stop the refresh, or quarantine the failing rows and mark the affected views. Summed over the faults,
viewers saw 242, 606 and 48 unmarked wrong views; the quarantine took 4,698 rows, all of them rows a fault added or
changed, but left a month total worse than loading on 11 faults. One author wrote the owners, severities, routes,
timings and row rules, knowing which checks fired in the earlier parts, so every result is a self-test of one
policy. Open `alerts-on-call.html`; the design is `DESIGN-reliability.md`, the frozen protocol
`reliability/protocol.json`, the results `reliability/results.json`, and the incident review and runbook written
from the results `reliability/incident-review.md` and `reliability/runbook.md`. One fault's landing time was read
wrongly in the first measured run and corrected after it; that fault was replayed again, its replays were identical
and no reported measure moved, as the design's last section records. S04's removed count reads 0 after the fix,
because its deleted rows count as present until the declared deletion time; no reported measure moved.

## Warehouse cost

A separate part loads 54 days of public City of Chicago ride-hail trips (January 1 to February 23, 2023, a one-in-eight
time-slot sample, 1,402,214 trips) one daily file at a time into three versions of the same models: a full rebuild, an
incremental model on a date key, and an incremental model on a date-partitioned table clustered by pickup area. On the
last run the full rebuild read 49 times the data and 49 times the rows of the partitioned model (86.5 MB against
1.8 MB), and the date-key model 20 times, because each run reads the trip ID column of the whole table for its delete (33.8 of
35.6 MB on the last run) and the trip date column for its watermark. Eight planted
faults were replayed over February: the partitioned model published what a full rebuild does on all eight, and the
date-key model skipped rows in four, by its design; of the scorecard's checks only a per-day count of landing rows
against the model saw it publish three days short. Checks on new trip dates only missed the late day's blank fares and a
faulty backfill, which the same checks on each morning's load batches caught. Bytes are counted from parquet file
metadata on one shared machine; no price is applied. Open `warehouse-cost.html`; the design is `DESIGN-warehouse.md`,
the frozen protocol `warehouse_cost/protocol.json` with `warehouse_cost/amendment-1.json` and
`warehouse_cost/amendment-2.json`, every file's address and SHA-256 `warehouse_cost/data-files.json`, the results
`warehouse_cost/results.json`, every run `warehouse_cost/runs.json`, and every run, check and query record
`warehouse_cost/records.zip`. Computed after the results: the split of the date-key model's reads into its
watermark, delete, load and published-table parts `warehouse_cost/date-key-split.json`, and what the two summary rules
added in amendment 7 changed `warehouse_cost/rule-effects.json`; DESIGN-warehouse.md's last section records both and
the predictions that did not hold (four of the six held).

## Table layers

A separate part lands the same 54 days of public trips (1,402,214 trips) as raw, cleaned and modeled Delta tables
(often called bronze, silver and gold), in four simulated batches a day, 216 in all, and runs the scorecard's checks on
every layer every morning over what that layer received since the morning before. Of seven faults replayed over
February, the checks caught 6 at the raw layer, 5 at the cleaned layer and 3 at the modeled layer, and the two checks
that compare layers caught none; a batch that arrived a day late with clean rows got past every layer. A replayed batch
is visible only at raw, because the cleaned layer keeps one row per trip; the modeled table, one row per day, cannot
run the duplicate or units checks and published both unit faults' wrong miles. With the late batch, raw and cleaned
were 0 batches behind yet complete only up to 30 hours back, missing one 6-hour window of February 17 (13,644 trips);
the modeled table published that day short for a day, 0.6955 times its 14-day median against the day-volume check's 0.6
bound, so the miss was narrow. All 7 predictions held, but most were safe: they follow from how each layer is defined,
or were known from the warehouse cost part's run of the same checks on the same files. The batches are simulated from daily files: no
streaming system was built or run. Open `table-layers.html`; the design is `DESIGN-layers.md` (its last section records
what changed after the measured run), the frozen protocol `table_layers/protocol.json`, the results
`table_layers/results.json`, every check, freshness, build and provenance record `table_layers/records.zip`, and a full
recount, computed after the results, at every February delivery of the out-of-order runs, which matched the recorded
windows behind, complete-through windows and holes (batches behind is covered by the unit test only),
`table_layers/fresh-recount.json`.

## Lakehouse recovery

The part after table layers runs a late file, a renamed column and a bad backfill on Databricks Free Edition, on real Delta tables, and asks
which control totals can prove a repair worked. An independent author who never saw the totals wrote 12 SQL repairs in one run, which ran as
written: 7 restored the data, row for row against a clean reference a team does not have. Of the other 5, outside totals on the published table
alone passed 2, because the published numbers were right and the cleaned table was not. Layer totals, outside totals on both tables, the row
fingerprint and the bundle of the last two passed none, but all 5 left the cleaned table's daily totals off the sender's, so these repairs
cannot rank those checks, and the bundle's zero follows from its definition: it covers every column the reference compares. Layer totals also
passed a do-nothing repair on the late file, because a file nobody read is missing from every layer alike, and in a self-test of 10 repairs
written with sight of the comparisons, a join by row position passed every total and only a row fingerprint caught it. The sender's totals are
computed from the clean sample, so they are right by construction. These counts use the reference declared before the runs, which scores only
the cleaned and published tables. The backfill instructions were ambiguous: on the author's reading, one blind backfill repair scored wrong
would be right and one scored right would be wrong, and every comparison, the bundle included, gets both of those wrong; that full recount was
computed after the results, in review. Of the 4 predictions on the blind repairs, 2 held; the other 8, on the clean reference, the do-nothing
repairs, the self-test repairs and the bundle's definition, follow from how the test was built, and all held (10 of 12 in all; the grouping was
made after the results).
Open `lakehouse-recovery.html`; the design is `DESIGN-lakehouse.md`, the
frozen protocol `lakehouse_recovery/protocol.json`, the repairs as written `lakehouse_recovery/blind-repairs.json`, every attempt's measurements
`lakehouse_recovery/records.json`, and the results `lakehouse_recovery/results.json`. `python -B -m quality.lakehouse_summary` rebuilds the results
from the records with no key; a new run needs a Databricks workspace of your own.

## What is measured

The historical clock is February 1, 2024 at 06:00. Clean arrivals are simulated at 01:00 on the day after each
trip date. Built-for faults: January 31 never arrives; 90 of January 30's fares are blanked; 25 January 30 rows
load twice; January 30 miles are multiplied by 1.609344. New faults: 2, 5 and 10 point rises in missing
fares on January 31; the 30 percent spike moved to January 22; 25 January 31 rows re-sent under new trip IDs;
January 31 arriving on time with half its rows. A fault counts as caught when at least one check fails.

Trust has a fixed denominator: freshness, completeness and uniqueness carry 25 points each, validity 15 and
anomaly 10. A group earns its points only when every check in it passes. A failed check in any group except
anomaly caps trust at 40; missing evidence caps it at 20.

Version 2 changes, exactly as declared:

- Day volume (completeness): a day fails with fewer than 0.6 times the median row count of the 14 loaded days
  before it.
- Content duplicates (uniqueness): fails when two rows share every field except the trip ID.
- Anomaly floor cut from 0.05 to 0.02, about two standard deviations of a day's missing-fare share on a
  300-row day. In version 1 the 0.05 floor set every bound, so the detector only repeated the 5% rule.
  Correction, computed after the results: the "two standard deviations" assumed a 3% missing-fare rate. The clean
  month's rate is 0.17% (17 of 10,000), so 0.02 is about 8 to 10 standard deviations of a day's share; the floor was
  a judgement, and it still set every version 2 bound (`floor_noise/results.json`).

The model lineage is
`raw_trips` to `stg_trips` to `trips` to `daily_trips`, computed from the dbt manifest; it shows dependency
exposure, not measured usage.

## Limits

- Twenty-six faults on one month of data: ten written directly into the fault code (plus one run with four of them
  at once) and sixteen written blind in two rounds. The counts describe these faults, not production recall.
- The units check compares miles with a synthetic metres field derived before the faults; two fields corrupted
  the same way would pass.
- Missing fares already exist in the public sample, so the 5% limit is a stated service assumption.
- The sample is a fixed set of 10,000 January 2024 records, not a probability sample of citywide travel.
  Original trip identifiers and precise locations are excluded.
- Overlapping anomaly windows are dependent, so clean-day counts are measurements on one month, not a
  false-alarm rate.
- Unaffiliated with the City of Chicago or dbt Labs. No employer data is used.

## Reproduce

Linux, Python 3.12 and uv. All Python dependencies are pinned in `requirements.lock` (dbt-core 1.12.5,
dbt-duckdb 1.11.0, DuckDB 1.5.6). The licensed data sample is inside the pinned dependency archive.

```sh
uv venv --python python3.12 .venv
uv pip sync --python .venv/bin/python requirements.lock
make scorecard
```

`make scorecard` runs all twelve scenarios, scores both versions, renders the pages and runs the tests, with no
API credentials. `python -B -m quality.recovery` reruns the pipeline recovery part and rewrites
`pipeline_recovery/results.json`. `python -B -m quality.cost run --repeat <1 to 5>` reruns the
pipeline cost jobs (one process per repeat, resumable), `python -B -m quality.cost summarize` rewrites
`pipeline_cost/results.json` and `pipeline_cost/jobs.json`, `python -B -m quality.cost_checks` reruns the two measurements added after the results, and
`python -B -m quality.render_cost` renders the page. `python -B -m quality.lineage run` replays the lineage and SLOs part and rewrites `lineage_slo/results.json` (deterministic; `python -B -m quality.lineage check` replays and compares it byte for byte), `python -B -m quality.lineage_figures` recomputes the figures added after the results, and `python -B -m quality.render_lineage` renders its page. `python -B -m quality.reliability run` replays the alerts and on-call part into `runtime/reliability/` (`--only <fault id>` limits it), `python -B -m quality.reliability summarize` rewrites `reliability/results.json`, `python -B -m quality.reliability check` replays everything and compares it byte for byte, `python -B -m quality.reliability monthend` checks that the February 1 morning reproduces the scorecard's recorded checks, and `python -B -m quality.render_reliability` renders its page, incident review and runbook. `python -B -m quality.warehouse_fetch <raw dir>` downloads the warehouse cost part's day files again, `python -B -m quality.warehouse prepare <raw dir>` normalizes them, `python -B -m quality.warehouse run <workload> --budget <seconds>` runs one workload until the budget is spent and resumes where it stopped (`clean` first, then the eight faults by name and `replay1` to `replay3`), `python -B -m quality.warehouse_summary` rewrites `warehouse_cost/results.json` and `warehouse_cost/runs.json` (from the records in `warehouse_cost/records.zip` unpacked into `runtime/warehouse/`, with no download), `python -B -m quality.warehouse_split` recomputes `warehouse_cost/date-key-split.json` from the clean run's table files, `python -B -m quality.warehouse_rules` recomputes `warehouse_cost/rule-effects.json` from the records, and `python -B -m quality.render_warehouse` renders its page. For the table layers part, `python -B -m quality.layers prepare <raw dir>` checks the same day files against `warehouse_cost/data-files.json` and normalizes them into `runtime/layers-days/`, `python -B -m quality.layers run <workload> --budget <seconds>` runs one workload until the budget is spent and resumes where it stopped (`clean` first, then the seven faults by name and `repeat`; DuckDB's Delta extension must be installed, and `LAYERS_DUCKDB_EXT` can point at its folder), `python -B -m quality.layers_summary` rewrites `table_layers/results.json` (from `table_layers/records.zip` unpacked into `runtime/layers/`, with no download), and `python -B -m quality.render_layers` renders its page. `make test` runs the fast tests only. The AI-answers test code is in the full project only; its saved answers are in
`gate/results.json`. Runs write to new directories under `runtime/runs/`.
The wording of some locked records (three code comments and a protocol heading) was edited after the runs, and the
hashes that seal them were updated; no result changed.
Page type and colour come from the vendored design system in `vendor/viz-design-system/`. See
[NOTICE.txt](NOTICE.txt) for attribution and [data/dependency.json](data/dependency.json) for the archive's
identity.

![Quality scorecard in a desktop browser](assets/scorecard.png)

Some files are packed in data-quality-scorecard-data-1.zip; unzip it here to restore the full export, which the manifest lists file by file.
