How Do I Run a Data Diff on dbt Pull Requests Without dbt Cloud Enterprise?
Build the same dev-versus-prod comparison from slim CI, defer and a few SQL queries
You can get a data diff on every dbt pull request without dbt Cloud Enterprise by building the changed models into a per-PR schema with slim CI, then comparing that schema to production with SQL or an open-source diff tool and posting the result as a PR comment. dbt's own Advanced CI announcement says the compare-changes feature was announced on October 8, 2024, and is generally available to dbt Cloud Enterprise customers. The pieces underneath it are not proprietary, and we walk through them below.
Key Takeaways
- •dbt's compare-changes feature in Advanced CI is limited to dbt Cloud Enterprise, according to the dbt announcement.
- •A data diff is built on slim CI: select changed models with state, defer unchanged parents to production, and build into a throwaway schema.
- •The diff itself is a comparison of two relations: row counts, added or removed keys, and value changes per column. You can write it in SQL or run an open-source tool.
- •Start the diff as a PR comment that informs the reviewer. Make it a blocking check only after you have seen its false-positive rate.
- •A diff shows what a change did to the data. It does not tell you whether the change was intended, so a human or policy still has to decide.
What Advanced CI actually gives you
The dbt announcement describes a feature called compare changes, which sits on top of slim CI. It compares the models built from your development branch against the latest production build so you can check a pull request's effect on the data before merging. According to the post, it reports rows and columns added, modified or removed, value changes within columns, data type and column order changes, primary key changes or duplicates, and the share of rows changed.
The same post says results are temporarily cached and shown in a git comment and in the run details, and that Advanced CI is opt-in and available only to Enterprise customers. That is the part teams on smaller plans ask about. The useful observation is that none of the underlying questions are exotic. Each is a query that compares two tables, which means a team can ask them without the managed feature.
We do not argue the managed feature is a bad deal. If you are already on Enterprise, using it removes plumbing you would otherwise own. This guide is for teams that are not, or that run dbt Core in their own orchestrator and want the same review signal in a pull request.
Step 1: Build only what changed into a per-PR schema
A data diff needs two things to compare: the production version of a model and the version built from the branch. Building the entire project for every pull request is slow and expensive, so the first step is slim CI. The dbt CI documentation describes the managed pattern: dbt builds and tests the changed models and their downstream dependencies in a temporary schema unique to the PR, named like dbt_cloud_pr_<job_id>_<pr_id>, and deletes it when the PR closes.
You can reproduce this in any CI runner. Fetch the production manifest from your last deploy, select with state:modified+, and set a schema name derived from the PR number, for example ci_pr_1704. Remember to drop the schema in a cleanup job on PR close. The dbt docs warn that a custom generate_schema_name macro can stop the managed cleanup from working, and the same applies to a hand-rolled version, so test the drop step once with a custom macro in place.
Step 2: Defer unchanged parents to production
Selecting changed models is not enough, because a changed model still needs its upstream parents to exist. The dbt defer documentation explains the mechanism: with --defer and --state set, dbt resolves a ref from the state manifest when the node is not selected and does not exist in your target. Both flags have to be set, or their environment variable equivalents.
For a diff, this matters in a specific way. Your branch build reads unchanged upstream tables from production, so any difference you measure comes from the code change and not from a stale copy of an upstream table. The defer docs also note a caveat we take seriously: selecting from mixed environments can give unexpected results, and tests with multiple parents, such as relationships tests, may run across environments. Review those cases before you trust a diff on a model that joins many sources.
Step 3: Compare the two relations
With the branch build sitting in ci_pr_1704 and production in analytics, the diff is three queries per changed model. First, compare row counts. Second, find keys that exist on one side only, using a full outer join on the primary key. Third, for keys on both sides, count rows where each column differs, using a null-safe comparison such as IS DISTINCT FROM where your warehouse supports it. Run the third query column by column, and cap the output to the top changed columns.
For a hypothetical example, suppose a PR changes a revenue calculation in an orders model. The diff might report no added or removed keys, but a changed net_revenue on a share of rows and unchanged values everywhere else. That is the shape of result a reviewer can act on: the change touched the column it was meant to touch. The numbers in that example are illustrative, not measured.
If you would rather not write the SQL, open-source diff tooling exists. One practitioner guide on dbt data quality tooling notes that the original open-source diff CLI was deprecated in May 2024 and that diffing from that vendor now requires its cloud product. It also describes newer open-source options built around dbt pull request workflows, where the developer picks which diffs to run and exports a checklist to the PR. Check the maintenance status of any tool before you adopt it.
Step 4: Post the result where the reviewer already is
A diff nobody reads is wasted compute. Write the output as markdown, keep it short, and post it as a single PR comment that your CI job updates on each push instead of adding a new comment every time. Lead with the summary a reviewer needs: models compared, keys added or removed, and the columns with value changes. Link to the full output as a CI artifact.
Size the diff to the question. For a large model, a full-table value comparison can cost more than the model's build, so sample or limit the comparison to a date range when the change is scoped to recent data. We recommend recording what you sampled in the comment itself, so a reviewer does not read a sampled result as a full one.
Step 5: Decide what blocks a merge
We recommend starting every diff as an informational comment. Blocking on a diff is much riskier than blocking on a test, because a legitimate change, such as a backfill or a corrected definition, is supposed to move values. A rule that fails on any change will be bypassed within a week.
Once you have watched the comments for a few weeks, promote the unambiguous cases to blocking checks: duplicate primary keys introduced by the branch, rows dropped from a model whose contract says rows should only be added, or a data type change on a column with downstream consumers. Leave value changes as comments that a reviewer acknowledges. This is the same per-domain approach we describe in Data Workers: approval is a setting per class of change, not one policy for everything.
Where an agent fits in
The five steps above are plumbing and judgment. The plumbing, such as wiring the CI job, managing the PR schema lifecycle and keeping the comment current, is repetitive work that a coordinated agent can take on. The Data Workers Pipeline Agent and Guardrail agent are built to work on those parts through MCP from Claude Code or Cursor, so a reviewer can ask "what does this PR change in the data?" and get the diff summary alongside lineage context.
The judgment still belongs to your team. In our setup the agent proposes and posts, and the autonomy dial for each domain decides whether it only comments or is allowed to block. We would not recommend letting any tool auto-merge a PR on diff results alone.
Frequently Asked Questions
Does slim CI require dbt Cloud?
No. Slim CI is built on --select state:modified+, --defer and --state, all documented in the dbt reference. The defer documentation says that passing --state enables the state: selection method and that together these features enable slim CI. You supply the production manifest and the runner yourself.
Is dbt Advanced CI only for Enterprise accounts?
According to the dbt announcement, the compare-changes capability is available to dbt Cloud Enterprise customers and is opt-in. Plans can change, so confirm against the current dbt documentation before you decide.
Can a SQL-only diff replace a managed one?
For most pull requests, yes: row counts, key differences and per-column value changes cover the common questions. You give up caching, a built-in UI and cross-warehouse handling. If your models are very large, plan the sampling strategy first.
Should the data diff block merges?
Not at first. We suggest starting as a comment and promoting only structural checks, such as duplicate keys, to blocking once you have seen how often the diff flags intended changes.