Request a demo

Glossary · Data observability and quality

What is data contract?

A data contract is an explicit, versioned agreement between the producer of a dataset and its consumers about its schema, meaning, quality and delivery, such as column types, allowed values, freshness and ownership, checked automatically so breaking changes are caught before they ship.

Also called: data contracts, schema contract, model contract, producer-consumer agreement

What goes into a contract

A useful contract is short and machine-checkable:

  • Schema: column names, types, nullability, and which columns are keys.
  • Semantics: what each field means, units, time zones and allowed values.
  • Quality: rules on the dimensions that matter, such as uniqueness of order_id or completeness of customer_id.
  • Delivery: freshness and volume expectations, usually as a data SLA.
  • Ownership and change process: who owns the data, how consumers are told about changes, and how long deprecated fields stay.

Contracts are usually YAML files next to the code that produces the data, versioned like an API. The Open Data Contract Standard (ODCS) is one published format for them.

Enforcing contracts on BigQuery

Enforcement happens at three points:

  1. At build time. dbt model contracts (contract: {enforced: true}) make dbt check before building a model that its columns and data types match the YAML, and pass them into the table DDL. On BigQuery, not_null constraints are enforced; primary_key and foreign_key can be declared but are not enforced.
  2. In the table definition. BigQuery itself enforces types and NOT NULL, and records keys as metadata:
CREATE TABLE sales.orders (
  order_id STRING NOT NULL,
  customer_id STRING NOT NULL,
  amount NUMERIC,
  currency STRING,
  created_at TIMESTAMP NOT NULL,
  PRIMARY KEY (order_id) NOT ENFORCED
)
PARTITION BY DATE(created_at);
  1. In production. Monitoring catches what CI cannot: a source system that starts sending new values, a schema change made outside the contract, or delivery that breaks the agreed freshness. Detecting these from logs and metadata means every table is covered, not only the ones with a contract file.

Why teams adopt them

Many painful data incidents start upstream: an application team renames a field, a vendor changes an export, and dashboards break days later. Contracts move the conversation to before the change. They also make data products possible: a dataset other teams can depend on needs a published interface, an owner and guarantees.

Pitfalls

  • Contracts nobody checks. A YAML file without CI or monitoring is documentation, and drifts.
  • Too much at once. Start with the schema and freshness of the few datasets that break most often.
  • Producer without incentive. Contracts work when producers own them; written only by consumers, they become wish lists.
  • No lineage. Knowing which consumers a change affects needs column-level lineage.

FAQ

What is the difference between a data contract and a data SLA?

An SLA covers service levels such as freshness and support. A data contract is broader: it also fixes the schema, the meaning of fields, quality rules and ownership, and is versioned and checked in CI. The SLA is often one section of the contract.

Does BigQuery enforce data contracts?

Partly. BigQuery enforces column types and NOT NULL (REQUIRED) columns, but primary and foreign keys are declared NOT ENFORCED and serve as metadata. Most contract rules are checked by tools around it: dbt model contracts at build time, tests in CI and monitoring in production.

Read next

Browse the full glossary

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.