guide
guide8 min read

Schema Checks in Pull Requests for Data: How an Agent Blocks Breaking Changes

A step-by-step setup that catches breaking column changes before merge and gives an agent the power to block them

To run schema checks in pull requests for data, compare the schema a pull request produces against the schema production serves today, classify each difference as breaking or safe, and make that comparison a required status check so a breaking change cannot merge. dbt's model contracts cover the first half (column names and data types are enforced at build time), and GitHub's protected branches cover the second (required status checks block the merge). An agent closes the gap in between: it reads the diff, works out who is affected, and decides whether to block.

Key Takeaways

  • •A schema check in a pull request compares the proposed schema to the production schema, not to the previous commit's code.
  • •Only a subset of schema changes are breaking: dropped or renamed columns, changed data types, and tightened nullability. Added nullable columns are usually safe.
  • •A required status check is what turns a schema check from advice into a gate. Without branch protection, a failing check is only a warning.
  • •The check should report blast radius (which downstream models, dashboards and consumers break), because 'a column was removed' is not enough for a reviewer to decide.
  • •An agent can own the block-or-allow decision for clear-cut cases and escalate ambiguous ones to a human, so reviewers approve one step instead of reading every diff.

Why schema checks in pull requests for data matter more with coding agents

Code review catches syntax and logic problems well. It catches schema consequences poorly, because the reviewer has to remember which of forty downstream models reads orders.customer_id and which dashboard filters on it. Coding agents such as Claude Code and Cursor raise the stakes: they produce more pull requests, faster, and they rename a column as readily as they fix a typo. The reviewer becomes the slowest node in the system.

We think the answer is not to review more carefully. It is to move the question 'is this change safe for consumers?' out of the reviewer's head and into a check that runs on every pull request. That is the premise of the rest of this tutorial.

Here is what counts as breaking, in our working definition. Treat it as a starting policy and adjust it to your consumers.

Schema changeUsually breaking?Why
Column droppedYesAny downstream select or join on it fails
Column renamedYesSame as a drop plus an add; consumers still reference the old name
Data type changed (for example int to string)YesCasts, joins and aggregations downstream can fail or change meaning
Nullable column tightened to not nullSometimesSafe for readers, but upstream writers may start failing
New nullable column addedUsually noExisting queries ignore it unless they use select *
Column description or tag changedNoMetadata only

Step 1: Declare what the schema is supposed to be

A check needs something to check against. For every model other teams read, declare the contract explicitly: column names, data types and constraints. In dbt this is the contract: enforced: true config plus a data_type on each column in the model's YAML, as described in the model contracts docs. If the model's SQL returns columns that do not match the declaration, the build fails.

Start with the models that have the most consumers, usually your gold or mart layer. Contracting every staging model on day one creates noise and teaches the team to ignore the check.

Step 2: Capture the production schema as the baseline

The comparison that matters is pull request versus production. Save a snapshot of production state on every deploy: dbt's manifest.json artifact works, or a dump of information_schema.columns for the schemas you care about. Store it where CI can read it, such as object storage or a CI artifact from the last main-branch run.

If you only compare against the base commit's code, a change that was merged but never deployed will look like the baseline. Comparing against what production serves removes that ambiguity.

Step 3: Run the check on changed models only

Building the whole project on every pull request is slow and expensive. dbt's continuous integration guidance describes building only modified nodes against production state, with a command like dbt build --select state:modified+ --defer --state ./prod-artifacts. The + pulls in downstream models, so a change to one model also exercises the models that read it.

Add a diff step after the build. It takes the baseline schema and the pull request's schema and emits a structured list: model, column, change type, old value, new value. Emit JSON, not log lines. The next steps, and the agent, need to read it.

Step 4: Classify each change and measure the blast radius

Apply the table above as rules to the diff, then attach consumers to every breaking change. Walk the lineage graph from the changed column downstream and list the models, dashboards, exports and notebooks that reference it. This is the difference between a check that says 'column removed' and one that says 'column removed, read by 14 models and 3 dashboards, one owned by finance'.

This is the job of our Schema Agent: it detects column-level drift, projects downstream impact and generates safe migrations. You can ask the same question interactively from your editor: 'What's the blast radius if I drop this column?' or 'Is the customer_id join safe after the migration?' Because every Data Workers agent is an MCP server, the question runs inside Claude Code or Cursor, using the Model Context Protocol, without opening another tool.

Step 5: Make the check a required status check

A check that can be ignored will be ignored. In your repository's branch protection settings, mark the schema check as a required status check on main, as described in GitHub's protected branches documentation. Also consider requiring branches to be up to date before merging, so a check that passed against an old baseline does not carry over to a newer main.

Decide the failure policy up front. We suggest three outcomes: pass (no breaking changes), fail (breaking change with live consumers), and needs-approval (breaking change with no consumers found, or a change the rules cannot classify).

Step 6: Let an agent make the block-or-allow call

Rules classify mechanically, but the decisions around them are judgment calls. Is the dropped column really unused, or is its consumer outside the lineage graph, such as a spreadsheet export? Did the author also open a migration pull request for the downstream models? Is this a deliberate versioned breaking change?

Give an agent the structured diff, the blast-radius list and read access to the pull request description and linked pull requests. Its output is a verdict with a reason posted as a pull request comment. For clear-cut cases it sets the status check directly: a dropped column read by live dashboards fails the check and links the affected consumers. For ambiguous cases it requests human approval and says exactly what it could not determine.

We run this with an autonomy dial per domain. In a domain where you trust the lineage, the agent blocks and allows on its own. In a sensitive domain such as finance, it only recommends and a named owner approves. The reviewer's job shrinks from reading every diff to approving the single step the agent flagged.

Step 7: Close the loop with a suggested migration

Blocking is half the value. When the check fails, the most useful comment includes a fix path: keep the old column as an alias for one release, add the new column alongside it, update downstream models in a follow-up pull request, then remove the old column after consumers have moved. Our Schema Agent generates this expand-and-contract sequence as a suggested migration, and the author can accept it from the same editor session where they opened the pull request.

We covered how the pieces of the swarm share context across incidents, lineage and governance in a separate post on the Incidents Agent and Pipeline Agent. The same shared context is what lets the schema check know which dashboards matter.

Common failure modes to plan for

  • •Noisy checks. If every pull request fails, people stop reading the result. Start with contracts on high-consumer models only.
  • •Stale baselines. If the production snapshot is not refreshed on every deploy, the diff reports changes that already shipped.
  • •Lineage blind spots. Consumers outside the graph (exports, ad hoc queries) are invisible. Maintain a short list of known external consumers and treat them as always affected.
  • •Rename detection. A rename looks like a drop plus an add. Flag matching type and position as a probable rename so the message says so.
  • •Agent overreach. Keep write access off by default. The agent comments and sets a status; it does not push commits unless you grant that explicitly.

Frequently Asked Questions

What is a schema check in a pull request for data? It is an automated CI step that compares the schema a pull request would produce against the schema currently in production, reports added, removed and changed columns, and fails the check when a change would break downstream consumers.

Do I need dbt model contracts to do this? No. Contracts make the expected schema explicit and enforce it at build time, which helps, but the core of the check is a diff between production and the pull request. You can build that from information_schema snapshots on any warehouse.

Can an agent really block a merge? Yes, through the same mechanism a test suite uses: a required status check. The agent sets the status to failed with a reason, and branch protection prevents the merge until it passes or a human with the right permission overrides it.

Should the agent have write access to the repository or warehouse? We recommend not by default. Our open-source edition is read-only by default, and writes plus approval workflows and audit trails are part of Pro. For schema checks, comment and status access is enough.

How do we handle intentional breaking changes? Version the model, announce the deprecation window, and have the check accept a documented exception, such as a label or an approved migration plan linked from the pull request. The agent verifies the exception exists and records it in the audit trail.

If you want to try this from your terminal, the Data Workers open-source edition runs locally, is Apache 2.0 and is read-only by default, so you can point the Schema Agent at a repository and ask it for the blast radius of a pull request before wiring up any CI gates.