guide
guide8 min read

Data Contracts in CI vs Runtime Checks: Failing Schema Drift at Pull-Request Time

Which contract clauses a pull request can block, and which ones only runtime can catch

To make schema drift fail at pull-request time, put the contract in version control next to the producer's code, and run a CI job that diffs the proposed schema against that contract and blocks the merge on a breaking change. dbt added model contracts in v1.5, which make the build fail when a model's columns or data types differ from the declared contract. CI catches the drift you can see in code. Runtime checks catch the drift you cannot, such as a source system that changes without a pull request.

Key Takeaways

  • •A pull-request check can only block drift that appears in a diff. Changes made in a source system you do not own never show up in one.
  • •Runtime checks are the backstop for upstream changes that skip your review process. They detect drift after it happens, so they need a fail-closed ingestion rule.
  • •dbt model contracts, introduced in v1.5, fail the build when column names or data types differ from the declared contract.
  • •Enforcement works best split by clause: structural clauses (columns, types, nullability) in CI, and value clauses (freshness, ranges, volumes) at runtime.
  • •A contract with no owner and no blocking check is documentation. Name the producer who gets the failing check and the consumer who gets notified.

Why the pull request is the cheapest place to fail

A failed check in a pull request costs the producer a few minutes. The same break in production costs every downstream consumer a morning of confusion, because the pipeline usually keeps running while the numbers go wrong. We covered that failure mode in our post on why a green DAG says nothing about the numbers. The pull request is the one moment when the person who made the change is still looking at it and can fix it without a ticket.

Practitioners describe the same pattern. One dev.to write-up on source systems that change without warning recommends failing ingestion on missing required columns, flagging new columns, and gating producer pull requests against the contract. Those are three different enforcement points. Only the last one is a pull-request check, which is why treating CI and runtime as alternatives leaves gaps.

The limit is visibility. A CI gate sees only the repository it runs in. If the producer is a SaaS vendor, a partner API or another team's database that you read through a replica, nobody opens a pull request in your repository when it changes. That is the case runtime checks exist for, and it is why we split the rest of this guide into five layers rather than picking one side.

Layer 1: Write the contract where the producer's code lives

The contract has to be a file in version control, in the producer's repository, reviewed by the same people who review the schema change. Our post on the Open Data Contract Standard shows the fields and a full YAML example. The point here is placement: a contract kept in a catalog UI or a wiki cannot fail a build, because the build does not read it.

For warehouse models, the native option is the model contract. In dbt, you declare the columns and data types in the model's YAML and set the contract to enforced, so the build errors when the compiled model does not match. That gives you a structural gate with no extra tooling. It covers column names, types and constraints on the platform's supported set. It does not cover meaning, freshness or volume.

Keep the contract small at first. Declare the columns consumers actually read, mark which are required, and give each a type. Every extra clause is something a producer can be blocked on, so add clauses when a consumer has been burned, not because the standard has a field for it. A contract that blocks every merge gets disabled within a month.

Layer 2: Gate the producer pull request on the contract

The gate is a CI job that does three things: build the proposed schema, compare it to the committed contract, and classify the difference. Removing a column, renaming one, narrowing a type or making a nullable column required are breaking changes and should fail the check. Adding an optional column is usually safe and should warn rather than block, so consumers see it without the producer being stuck.

Add a data-diff step for changes that keep the schema intact but change values. Open-source diff tooling such as Recce, published on PyPI at version 0.38.0, compares model output between the base branch and the pull request, so a reviewer sees row-count and value changes before merging. A contract says what the shape must be. A diff shows what the change actually did to the data.

Make the failure message actionable. The check should name the broken clause, list the downstream consumers registered against it, and say who to contact. If the producer has to open a lineage tool to work out who is affected, they will ask for an override. Our deprecation-policy post covers the same idea for dropping tables: show the readers before the change, not after.

Layer 3: Keep runtime checks for what the diff cannot see

Runtime checks run when data arrives. They cover three things a pull request cannot: upstream systems that change outside your review process, value-level violations such as nulls in a required column or an out-of-range amount, and operational clauses like freshness and volume. Fail ingestion closed on a missing required column. Quarantine rows rather than loading them with silent nulls.

The difference matters for agents as well as dashboards. An agent that reads a table after a silent change keeps answering with confidence. We wrote about this in why agents keep working on bad data after a schema change. A runtime check that blocks the load gives the agent an explicit failure to reason about, instead of a quietly wrong table.

Treat the runtime layer as detection with a defined response. Each clause should say what happens on violation: block the load, quarantine the rows, or alert and continue. Without that, the check is a log line. Put the severity in the contract itself so producers and consumers agree on it before the first incident, not during it.

Layer 4: Decide who owns each clause

Split ownership by direction. The producer owns structural clauses, because only the producer can fix a column rename. The consumer owns the expectations on values it depends on, because the producer does not know which fields a revenue report needs. Our guide on where dbt contract enforcement stops and producer-consumer contracts begin walks through that boundary in six steps.

In CI, this means two kinds of check. The producer's pull request runs the producer's contract. A consumer's pull request, for a model that depends on an upstream table, runs a consumer-side check that the columns it reads still exist in the upstream contract. Both fail at review time, which is the whole goal.

Write the escalation path into the contract too. When a breaking change is intentional, the producer needs a versioned release: publish the new version alongside the old, notify consumers, and set a retirement date. Without a version path, the only way past the gate is an override, and overrides are how drift gets back in.

Layer 5: Let an agent close the loop from failure to fix

A failed check still needs someone to work out the blast radius and write the fix. That is where we use agents. The Schema Agent detects column-level drift and projects downstream impact, so the pull-request comment can list affected consumers without a manual lineage search. It also generates the migration for the consumer side of a breaking change.

The Pipeline Agent handles the pipeline half: it updates the ingestion or transformation step that read the old column, and opens the change for review. In the open-source edition both agents are read-only by default, so they propose and explain. Writes, approval workflows and audit trails come with Pro. You decide per domain how much to hand over.

Both agents run as MCP servers, so you can ask from Claude Code or Cursor, in a prompt like "What's the blast radius if I drop this column?" or "Is the customer_id join safe after the migration?" You get the answer inside the pull request workflow, not in a separate dashboard. The contract stays the source of truth. The agents read it and act on it.

Frequently Asked Questions

Should data contracts be enforced in CI or at runtime?

Both, split by clause. Structural clauses such as column names, types and required fields belong in CI, where the producer can fix them before merge. Value and operational clauses such as freshness, ranges and volume belong at runtime, because they depend on the data that arrives. CI alone misses upstream changes made outside your repository. Runtime alone finds problems after consumers have read them.

Do dbt model contracts replace a data contract standard?

No. A dbt contract enforces the shape of a model at build time, which is a useful structural gate. A contract standard such as ODCS also describes ownership, quality expectations, service levels and terms between producer and consumer. Use the dbt contract as the enforcement mechanism for the structural part, and keep the wider contract in version control beside it.

What should fail the build and what should only warn?

Fail on breaking changes: a removed or renamed column, a narrowed type, or a nullable column made required. Warn on additive changes such as a new optional column, so consumers are told without the producer being blocked. Put these severities in the contract itself so every producer gets the same answer and nobody has to negotiate it in review.