published fresh until

How do I test a dbt pipeline for missing or duplicate rows with unit tests?

Summary When your dbt pipeline has missing, duplicate, or incorrect rows, use data tests and reconciliation, unit tests, failing-row inspection, join fan-out checks, and bad-input cleanup. Running tests in CI has no tested answer yet.

Not for cleaning one messy file, see case-import-messy-csv-excel-validation-error-report

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The case

You have a pipeline that loads data into a warehouse and transforms it with dbt and SQL. Reports sometimes show too few or too many rows, or totals that look wrong. Success looks like: duplicates and gaps are caught by tests before anyone reads a report, a failing test shows which rows broke it, tricky logic has fixtures, and agent-written models are checked by rules instead of by eye. Stack: dbt and SQL.

This is a map, not new advice: every linked row points to an existing WhatWorks thread. Nobody here ran this whole build; the Status column says what each linked thread rests on. "Tried" would need a linked trial report, and none of the linked threads has one yet.

Parts, in the order people do them

PartWhat to useStatusLink
Tests on keys, nulls and countsdbt data tests, row-count thresholds, source-to-target reconciliationDocumented: vendor or primary source, not tried (no linked trial)How do I test my pipeline so missing or duplicate rows get caught?
Logic with tricky casesdbt unit tests with mocked inputsDocumented: vendor or primary source, not tried (no linked trial)How do I write dbt unit tests for a model's logic?
See which rows failedstore_failures and the audit schemaDocumented: vendor or primary source, not tried (no linked trial)My dbt test fails: how do I see which rows failed?
Join fan-out and wrong totalsCheck grain before and after each joinDocumented: vendor or primary source, not tried (no linked trial)How do I check AI-written SQL for join fan-out and wrong totals?
Agent-written modelsContext, skills and deterministic checksDocumented: vendor or primary source, not tried (no linked trial)How do I stop my agent writing sloppy dbt models?
Messy inputs before the loadProfile first, clean with a script and an auditDocumented: vendor or primary source, not tried (no linked trial)How do I have my agent clean a messy CSV without losing rows?
Compare two extractsMerge and list missing and changed rowsDocumented: vendor or primary source, not tried (no linked trial)How do I compare two spreadsheets and list missing and changed rows?
Run the dbt tests automatically in CINo tested answer yetNo tested answer yetnone (see open request)

Where it breaks

Open questions

  • Parts marked "No tested answer yet" are gaps in WhatWorks; ask for them with the request tool so an editor can look: running dbt tests in CI on every change.

Status key

Documented means the linked thread cites official docs or a vendor source and was not run. Untried means the linked thread rests on a community post or on suggestions and was not run. Tried would need a linked trial report, and none exists yet.

As of October 2026. cleaning one messy upload, see case-import-messy-csv-excel-validation-error-report; charts and dashboards, see case-kpi-dashboard-charts-postgres-scheduled-refresh.

Started from a post by @WhatWorks editors, packaged by the editor.

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I test a dbt pipeline for missing or duplicate rows with unit tests?
Summary: When your dbt pipeline has missing, duplicate, or incorrect rows, use data tests and reconciliation, unit tests, failing-row inspection, join fan-out checks, and bad-input cleanup. Running tests in CI has no tested answer yet.
Copy for agent
get the whatworks thread case-test-dbt-data-pipeline-missing-duplicate-rows-unit-tests and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread case-test-dbt-data-pipeline-missing-duplicate-rows-unit-tests
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp