Skip to content

Data contract template: a minimal YAML contract you can validate in CI

By Datanest · Published · Updated

A data contract is a written agreement between the team that produces a dataset and the teams that read it: what columns exist, what they mean, how often the data is updated, and who to ask when something looks wrong. It only helps if a machine can check it, which is why contracts are written as YAML or JSON rather than as a wiki page.

Instead of inventing a format, this template uses the Open Data Contract Standard (ODCS), an open standard maintained by the Bitol project under the Linux Foundation's LF AI & Data. It is published under the Apache 2.0 licence, and its current version at the time of writing is v3.2.0 (released 8 September 2026). Check the ODCS site for newer versions before you adopt it.

How this was checked. The contract below validates against the official ODCS v3.2.0 JSON Schema, and both scripts were run on example files (a valid contract, an invalid one, a breaking change without a major version bump, and one with it). The names, team and email address are made-up examples.

The template

contracts/orders.odcs.yaml

# contracts/orders.odcs.yaml
apiVersion: v3.2.0
kind: DataContract
id: 3f0c2a4e-8b61-4d0a-9c57-1a2e6b9d7f10   # any unique id; a UUID is a good choice
name: orders
version: 1.2.0
status: active
domain: sales
description:
  purpose: One row per customer order, after payment is confirmed.
  limitations: Orders that fail payment are not included.

schema:
  - name: orders
    physicalType: table
    description: Confirmed customer orders.
    properties:
      - name: order_id
        logicalType: string
        required: true
        unique: true
        primaryKey: true
        description: Stable order identifier.
      - name: customer_id
        logicalType: string
        required: true
        description: Identifier of the customer who placed the order.
      - name: order_total
        logicalType: number
        logicalTypeOptions:
          minimum: 0
        physicalType: decimal(12,2)
        required: true
        description: Order total including tax, in the order currency.
      - name: created_at
        logicalType: timestamp
        required: true
        description: When the order was confirmed.

team:
  name: sales-data
  description: Owns the orders dataset. Use the team channel, not a person.

support:
  - channel: sales-data-team
    tool: email
    url: mailto:[email protected]

slaProperties:
  - property: frequency
    value: 1
    unit: d
    element: orders.created_at
    description: The table is refreshed at least once every 24 hours.

What each block is for

  • apiVersion, kind, id, version: apiVersion is the version of the standard; version is the version of your contract and should follow semantic versioning. id is required.
  • schema: the part you can check automatically. required, unique and the logical type catch most accidents, and logicalTypeOptions adds simple value rules such as minimum: 0.
  • team and support: someone to ask when the data looks wrong. Point at a team channel so the contract survives people changing jobs.
  • slaProperties: ODCS defines frequency ("frequency of update") and latency among other properties. Write the promise as something you can measure.

ODCS does not have a field for a change policy, so keep that in your process: a change that removes or renames a column, changes a column's type, or makes an optional column required is a breaking change and needs a new major version and notice to consumers. Adding an optional column or documentation is not breaking.

How to enforce it

1. Validate the contract file in CI

Download odcs-json-schema-v3.2.0.json from the schema/ folder of the v3.2.0 release in the ODCS repository and check every contract against it. ODCS publishes an official JSON Schema with every release.

validate_contract.py

"""Validate a data contract file against the official ODCS JSON Schema.

Usage: python validate_contract.py contracts/orders.odcs.yaml
Needs: pip install pyyaml jsonschema
Schema: odcs-json-schema-v3.2.0.json, from the schema/ folder of the v3.2.0 release in
https://github.com/bitol-io/open-data-contract-standard
"""
import json
import sys

import yaml
from jsonschema import Draft201909Validator

SCHEMA_FILE = "odcs-json-schema-v3.2.0.json"

schema = json.load(open(SCHEMA_FILE))
contract = yaml.safe_load(open(sys.argv[1]))

errors = sorted(Draft201909Validator(schema).iter_errors(contract), key=lambda e: list(e.path))
for e in errors:
    where = "/".join(str(p) for p in e.path) or "(root)"
    print(f"{sys.argv[1]}: {where}: {e.message}")
sys.exit(1 if errors else 0)

2. Block breaking changes without a major version bump

Compare the contract on your main branch with the one in the pull request. This script covers the three breaking changes above (removed column, changed type, optional made required). It is deliberately small; extend it for your own rules.

check_breaking.py

"""Compare two versions of a contract and fail if a breaking change was not
accompanied by a major version bump.

Usage: python check_breaking.py old.odcs.yaml new.odcs.yaml
"""
import sys

import yaml


def columns(contract):
    out = {}
    for table in contract.get("schema", []):
        for prop in table.get("properties", []):
            out[(table["name"], prop["name"])] = prop
    return out


def major(contract):
    return int(str(contract["version"]).split(".")[0])


old = yaml.safe_load(open(sys.argv[1]))
new = yaml.safe_load(open(sys.argv[2]))
old_cols, new_cols = columns(old), columns(new)

breaking = []
for key, o in old_cols.items():
    n = new_cols.get(key)
    if n is None:
        breaking.append(f"removed or renamed column {key[0]}.{key[1]}")
        continue
    if o.get("logicalType") != n.get("logicalType"):
        breaking.append(f"type of {key[0]}.{key[1]} changed: {o.get('logicalType')} -> {n.get('logicalType')}")
    if not o.get("required", False) and n.get("required", False):
        breaking.append(f"{key[0]}.{key[1]} changed from optional to required")

if breaking and major(new) <= major(old):
    for b in breaking:
        print("BREAKING:", b)
    print(f"Version is {new['version']} (was {old['version']}): bump the major version or revert the change.")
    sys.exit(1)
print("OK" if not breaking else "Breaking changes present and the major version was bumped.")
pip install pyyaml jsonschema
python validate_contract.py contracts/orders.odcs.yaml
python check_breaking.py old/orders.odcs.yaml contracts/orders.odcs.yaml

3. Monitor freshness

Freshness is the promise consumers notice first. Query the table's latest timestamp on a schedule and alert when it is older than the update frequency in the contract.

SELECT max(created_at) AS latest FROM orders;
-- alert when latest is older than the frequency you promised (here: 24 hours)

Want it implemented for Databricks?

The Data Contract Framework (59 USD) is a Databricks-oriented implementation with its own YAML contract spec (not ODCS): a CLI generator and validator, a contract registry, schema-validation, SLA-monitoring and breaking-change-detection notebooks, contract templates for API, database and file sources, and tests (20 files). It lists Python 3.9+, PyYAML 6 and jsonschema 4 as prerequisites.

Related: a Databricks Asset Bundles project template.