guide
guide8 min read

Data Contract Template YAML: A Working Example for Warehouse Tables

A copyable contract for one warehouse table, plus the steps to enforce it in CI and from your coding agent

A data contract template in YAML is a single versioned file that states a table's schema, quality rules, freshness SLA, owner and consumers, so a machine can check it on every change. The most widely used open format is the Open Data Contract Standard, a YAML spec maintained under the Bitol project. The template below follows its structure, so you can adapt it without inventing a format of your own.

Key Takeaways

  • •A data contract is a YAML file in git, not a wiki page: it has an owner, a version, a schema, quality checks and an SLA, and CI can fail a pull request that breaks it.
  • •Start with one gold table that has real consumers. Contracting every table at once produces files nobody maintains.
  • •Keep the contract small: required columns and types, a few quality rules, one freshness SLA and a named owner cover most of the value.
  • •A contract only matters if it is enforced. Run it in CI against the warehouse, and let your coding agent read it before it edits a model.
  • •Model-level contracts in a transformation tool (see dbt's model contracts docs) enforce shape at build time. A standalone YAML contract also covers ownership, SLAs and semantics.

A data contract template YAML you can copy

The template describes a hypothetical analytics.orders table in the gold layer. Treat the field names as a starting point and check them against the version of the standard you adopt, because the spec has changed between major versions. The skeleton is easiest to read as a field reference, so we list each top-level block, an example value and what it is for.

BlockExample valueWhat it is for
apiVersion / kindv3.0.0 / DataContractDeclares which version of the spec the file follows, so tooling can validate it.
id, name, versionorders-gold, orders, 1.2.0Stable identity plus a semantic version that changes when the contract changes.
statusactiveLifecycle state: draft, active or deprecated.
domain / dataProductcommerce / ordersWhich business domain owns the data.
description.purposeConfirmed customer orders, one row per orderOne sentence a consumer can read and understand.
schema[].propertiesorder_id, customer_id, order_total, created_atColumns with logical type, required, unique, primary key and classification flags.
qualityrow_count > 0, null rate on customer_id = 0Checks that run against the real table.
slaPropertiesfreshness 60 minutes, retention 3 yearsThe delivery promises consumers can plan around.
team / supportcommerce-data, #data-ordersA named team and a channel, so a breaking change has a person to ask.

In the file itself, the schema block lists the table orders with a physicalType of table. Each entry under properties carries a name, a logicalType (string, integer, number, timestamp), and flags such as required: true, unique: true and primaryKey: true. A column holding personal data gets a classification value such as pii, which matters later for access reviews. The slaProperties block holds entries like property: freshness, value: 60, unit: m. That is the whole template: roughly 50 lines of YAML for a table with a dozen columns.

Step 1: Pick one warehouse table and name its owner

Choose a gold-layer table that other teams already query: orders, customers, revenue. The test is simple: if this table broke tonight, would someone besides you notice by morning? If yes, it is a good first contract. Write down the owning team and the consumers you know of. Query logs in the warehouse show you real consumers faster than a survey does, and they often reveal dashboards or notebooks the owner has never heard of.

We recommend against starting with a raw or staging table. Those change shape often and have no stable consumers, so the contract gets rewritten weekly and people stop trusting it.

Step 2: Declare the schema with required, unique and classified columns

List every column consumers depend on, not every column in the table. For each one set the logical type and mark required, unique and primaryKey where they apply. Add a classification for anything personal or sensitive. This is where the contract starts to differ from a warehouse DDL: the DDL says what the table is, while the contract says what you promise not to change without telling anyone.

Be strict on keys and timestamps, and loose on columns you expect to churn. A common mistake is promising NOT NULL on a column the upstream source cannot guarantee. The contract then fails on day one and gets disabled.

Step 3: Add quality rules that match how the table breaks

Quality rules in the template run as checks: a row count floor, a null-rate ceiling on key columns, an accepted-values list for status fields, a uniqueness check on the primary key. Pick rules from your own incident history. If the last outage was a duplicated load, write a uniqueness rule. If it was a silent drop in volume, write a row-count bound relative to the previous day.

Three to six rules per table is plenty. Each additional rule is one more thing that can page someone, so every rule should map to a failure someone would act on.

Step 4: Set the SLA and the breaking-change policy

The slaProperties block records the promises that are not about shape: how fresh the table is, how long history is kept and when it is available. Write numbers you actually meet today. An SLA of 15 minutes that you hit 60% of the time teaches consumers to ignore the SLA.

Add a short note on what counts as a breaking change. Our convention is simple: removing or renaming a column, narrowing a type, or tightening a nullable column to required is breaking and bumps the major version. Adding an optional column is a minor bump. The version field is how a consumer's pipeline knows whether it can upgrade without reading the diff.

Step 5: Validate the contract in CI

Put the YAML next to the code that builds the table, and run two checks on every pull request. First, validate that the file conforms to the spec. The open-source datacontract-cli can lint a contract and test it against a live data source. Second, diff the changed contract against the main branch and fail the build when the diff contains a breaking change without a major version bump.

If you already use model contracts in your transformation layer, keep them. They enforce column names and types when the model builds. The YAML contract sits above them and holds the things a build cannot know: the owner, the SLA, the classification and the consumers. We see the two as layers, not rivals.

Step 6: Let your coding agent read the contract before it edits the model

Most contract violations now start in an editor, not a deploy script. An engineer asks an AI coding agent to rename a column or change a join, and the agent has no idea who consumes the table. The fix is to make the contract readable by the agent. Because the file is plain YAML in the repo, Claude Code and Cursor can already read it. Add a line to your project instructions file telling the agent to open the contract for any table it modifies and to stop if the change would be breaking.

For questions that need more than the file, such as "What's the blast radius if I drop this column?" or "Is the customer_id join safe after the migration?", the agent needs lineage and usage data. Our Schema Agent exposes those through MCP, the protocol Claude Code and Cursor use to call external tools, so the question gets answered with downstream impact before the edit is made. You can read more about the Data Workers agents on our site.

Step 7: Version the contract and review it like code

Treat contract changes as reviewed changes. Require approval from the owning team and, for breaking changes, from a named consumer. Keep a changelog entry in the PR description with the version bump and the reason. When a contract is deprecated, set status: deprecated and keep it for one release cycle so consumers have time to move.

Contracts drift when nobody owns them. Assign a review date and let CI warn when a contract has not been touched in six months while the table's schema has. That mismatch usually means the file describes a table that no longer exists.

Where a static YAML file stops being enough

A YAML contract tells you what should be true. It does not tell you why a check failed at 3 a.m., which upstream change caused it, or who is affected. That gap is where the human time goes. In our experience the work after detection, tracing root cause and mapping impact, is what takes hours. Our Incidents Agent and Schema Agent work from the same contract: when a quality rule fails, they trace the cause and list the affected consumers instead of leaving that to whoever is on call. In early pilot testing, 60% of incidents auto-resolve before a human is notified, which is our own pilot figure, not an industry benchmark.

We covered how our agents keep metadata current in a separate post on the catalog. The same idea applies here: the contract is only as useful as the context around it, and that context changes daily.

Frequently Asked Questions

What is a data contract template in YAML? It is a reusable YAML file that defines the schema, quality rules, SLAs, ownership and metadata for a dataset. Teams copy it for each table and fill in the specifics. The Open Data Contract Standard is the main open spec behind such templates.

Which YAML format should I use for a data contract? We suggest the Open Data Contract Standard unless you have a strong reason not to. It is open, versioned and supported by open-source tooling such as datacontract-cli, so you avoid maintaining a custom format and the validators that go with it.

How many tables should have a data contract? Start with the handful of gold tables that other teams depend on. Expand when the first contracts are being enforced and updated. A contract that is never enforced is documentation, not a contract.

Do data contracts replace dbt tests or model contracts? No. Model contracts and tests check shape and logic at build time. A YAML contract adds ownership, SLAs, classification and consumer expectations, and it can be enforced against the live table. Most teams run both.

Can an AI coding agent write the contract for me? It can draft one from a table's schema and query history, and Claude Code does this well when it can read your DDL. A human owner still has to confirm the SLA, the quality rules and what counts as breaking, because those are commitments, not descriptions.