Build

Rulebook

The rulebook holds the shared standards every data product must meet. It is a versioned set of policy rules. The same rules run on a laptop (wam validate), in the editor (SARIF) and in every CI pipeline, so a product that breaks a blocking rule cannot be merged or released. This page covers the types of rules, every built-in rule, how an organisation tunes the rulebook with a policy pack, how exceptions work, and how to write your own rules.

How a rule works

A rule is a small Python class with an ID, a title, a scope and a default severity. It receives a context and returns findings:

  • The context holds the parsed product.yaml, the SQL files and their analysis (columns, tables read, lineage, expression fingerprints), the previous version from main when there is one, the repository files, today's date, and optional workspace facts such as groups, the dependency graph, row counts and upstream classifications.
  • A finding has the rule ID, a severity, a message, a file, a line and a remediation hint.

The engine runs every rule whose scope belongs to the requested gates, applies the policy pack, then applies waivers. The product is blocked if any block finding is left unwaived.

Types of rules

By scope: when the rule runs

ScopeGateRunsTypical checks
static1Locally and in CI, from the files alone, in millisecondsNames, owner, descriptions, classifications, secrets, SQL hygiene, regulatory mappings
build2In CI on the pull request, compared with mainContract changes, keys, required tests, PII lineage, declared inputs, cycles, consumer expectations
deploy4Before a release is promoted to productionDeploy identity, human approval of AI changes, external sharing profile
runtime5On every run in the workspaceQuality checks, freshness and grant drift (Enterprise)
continuous6Scheduled scans of the whole meshRetention, unused ports, duplicates (Enterprise)

Gate 3 is the test deploy: the bundle deploys to the test workspace and runs on sample data. It is a CI step, not a set of rules.

By severity: what a finding does

SeverityEffect
blockFails wam validate (exit 1) and the CI gate.
warnReported, annotated on the pull request, never fails.
infoReported only.

Some rules choose their severity by tier: DP011 blocks at P1–P2 and warns at P3–P4, and DP055 blocks only at P1. A policy pack can change any rule's severity.

Offline and online rules

Most rules need only the files, so they give the same answer everywhere. Online rules also need facts from the workspace, such as row counts (DP045) or registered consumer expectations (DP063). Offline, they are listed as skipped and do not fail. CI collects the facts and runs them.

Core and Enterprise rules

Core rules ship with the CLI. Enterprise rules come with the Enterprise package and are loaded automatically when it is installed: DP110 to DP112 (the Regulated pack), plus the runtime and continuous services. Your own rules are a third source, loaded the same way.

Catalogue

IDScope · gateDefaultRuleFix
DP001static · 1blockProduct and port names are snake_case, 2–63 charactersRename
DP002static · 1blockowner is an existing group with at least two members (membership checked online)Use a team group
DP005static · 1blockNo secrets in product.yaml or SQL: password, token or API-key assignments, Databricks tokens, storage account keys, private keysUse a secret scope
DP007build · 2blockA breaking change (port or column removed, type or keys changed) needs a new port versionPublish <port>_v<N+1>
DP010static · 1blockProduct and port descriptions have at least 40 charactersDescribe purpose and use
DP011build · 2block at P1–P2, warn otherwiseEvery published column is describedwam describe
DP020static · 1blockEvery column of a source product has a classificationAdd classification
DP021build · 2blockA column that inherits PII through lineage is classified, or marked x-deidentified with a justificationAdd pii or de-identify
DP030static · 1blockNo physical catalog or environment names in SQLUse {{ ref() }}
DP031static · 1warnNo more than five template variables in one SQL fileSimplify
DP033static · 1blockNo SELECT * in port SQLList the columns
DP040build · 2blockmerge, scd2 and window ports have keys; window has a watermarkAdd keys, load.watermark
DP045build · 2, onlinewarnsnapshot on a table above 50 million rowsUse merge or window
DP050build · 2blockNo dependency cycles between productsExtract the shared logic
DP055build · 2block at P1, warn otherwiseSQL reads only declared inputsDeclare the input
DP060build · 2blockThe tests required for the tier are presentAdd the listed checks
DP061build · 2blockAt most two live versions per portRetire the oldest
DP062build · 2warnSemantic change: a column's SQL expression changedDeclare a bugfix or bump the version
DP063build · 2, onlineblockThe change keeps every registered consumer expectationAgree with the consumer
DP075deploy · 4blockExternally shared ports are P1 or P2 and expose no restricted columnsDe-identify, raise the tier
DP090deploy · 4blockProduction deploys run as a service principalDeploy from CI
DP095deploy · 4blockAI-generated changes have a human approverGet a review
DP110build · 2block for high-risk AIHigh-risk AI training data represents the reference population (Enterprise)Rebalance or document
DP111static · 1blockRegulatory ports map or waive every mandatory data point of their template (Enterprise)Complete mapping
DP112build · 2blockPorts that implements: a group contract conform to it (Enterprise)Align the port

Enterprise services enforce more standards outside the gates: grant drift (DP070, manual grants outside the access workflow are reverted) and duplicate-port candidates (DP085). Retention enforcement (DP076) and retiring unused ports (DP080) are on the roadmap and not yet enforced.

Each run also blocks on SQL that does not parse. These findings are reported under the rule ID SQL.

Policy packs

An organisation does not edit the rules. It publishes a policy pack: a versioned YAML file that picks which rules run and how strictly. Every repository pins one pack, and CI passes it to wam validate --pack.

name: acme-standards
version: "1.4"
disabled: [DP031]              # rules that do not run at all
severity:                      # override a rule's severity: block | warn | info
  DP011: block                 # undescribed columns block at every tier
  DP062: block
grace:                         # a newly blocking rule only warns until this date
  DP021: 2027-02-01
defaults:                      # configuration defaults, a layer below domain wam.yaml
  tier: P2
  compute: {performance_target: STANDARD}
KeyTypeEffect
name, versionstringIdentify the pack. Reports show it as name@version, and products can record it in policy_pack:.
disabledlist of rule IDsThese rules are not run.
severitymap: rule ID → block | warn | infoReplaces the rule's default severity, including tier-dependent ones.
gracemap: rule ID → dateUntil that date, block findings of the rule are shown as warnings with (blocking from <date>). This lets you tighten a standard without breaking every team the same day.
defaultsmapConfiguration defaults for every product, merged between the platform defaults and the domain wam.yaml.

Packs can extend each other. A group pack sets the baseline and a business-unit pack adds to it: disabled rules are combined, while severities and defaults from the child win. Changing the pack version is itself a pull request. The upgrade impact check (whatamesh.policy.engine.upgrade_impact) compares the old and new pack across the mesh and lists every product that would newly block, with a 30-day grace date by default.

Waivers

When a product cannot meet a rule yet, the owner adds a waiver to product.yaml and the steward approves it in the pull request:

waivers:
  - rule: DP060
    reason: Reconciliation against the actuarial system arrives with release 2027.1
    approved_by: steward-risk
    expires: 2027-06-30

A waived finding is still reported, marked (waived), and stops blocking. SARIF output leaves it out, so code scanning stays clean. Once expires passes, the finding blocks again with (waiver expired <date>). A waiver covers every finding of that rule in the product, so keep the reason specific.

Adding your own rules

Custom rules are ordinary Python classes in a package your organisation owns. They are registered through an entry point, so the CLI and CI load them without a fork.

1. Write the rule. Subclass Rule, set id, title, scope, severity and remediation, and yield findings from evaluate. Use your own ID prefix so you never collide with built-in IDs; the registry refuses duplicates.

# acme_rules/rules.py
from collections.abc import Iterable

from whatamesh.policy.base import Context, Finding, Rule, Scope, Severity
from whatamesh.spec.models import Tier


class ACME001CostCentre(Rule):
    """Every P1 or P2 product carries a cost centre for chargeback."""

    id, title, scope = "ACME001", "P1 and P2 products declare a cost centre", Scope.static
    severity = Severity.block
    remediation = "Add `x-cost-centre: <code>` to product.yaml."

    def applies(self, ctx: Context) -> bool:
        return ctx.spec.tier in (Tier.P1, Tier.P2)

    def evaluate(self, ctx: Context) -> Iterable[Finding]:
        if "x-cost-centre" not in ctx.spec.extensions:
            yield self.finding("product has no x-cost-centre")


class ACME002NoTimestampKeys(Rule):
    """Keys on timestamps make merges non-deterministic."""

    id, title, scope = "ACME002", "Keys are not timestamps", Scope.build
    severity = Severity.warn

    def evaluate(self, ctx: Context) -> Iterable[Finding]:
        for port in ctx.spec.outputs:
            for key in port.keys:
                col = port.columns.get(key)
                if col and col.type and col.type.startswith("timestamp"):
                    yield self.finding(f"port '{port.name}' uses timestamp column '{key}' as a key")


RULES = [ACME001CostCentre, ACME002NoTimestampKeys]

Useful parts of the context:

AttributeContent
ctx.specThe validated product.yaml (ProductSpec): outputs, inputs / input_ports, tier, kind, extensions (the x- keys) and so on
ctx.sql / ctx.sql_infoSQL text per file, and its analysis: columns, refs, lineage, expressions, select_star, hardcoded
ctx.previousThe version on main, for build rules that compare (None for a new product)
ctx.repo_filesRepository files the rule may scan
ctx.todayThe evaluation date, so time-based rules stay testable
ctx.online, ctx.facts, ctx.groups, ctx.graphWorkspace facts. Set online = True on the rule if it needs them, and it is skipped offline
ctx.deployFor deploy rules: target environment, identity, approvers

2. Register the package. Point the whatamesh.rules entry point at the class or the list:

# pyproject.toml of acme-rules
[project.entry-points."whatamesh.rules"]
acme = "acme_rules.rules:RULES"

3. Install it wherever validation runs. Install it next to whatamesh in developer environments and in the CI image (pip install acme-rules). The engine loads every entry point once per process. A plugin that fails to import prints whatamesh: skipped rule plugins: ... and never breaks validation. Pin the package version in CI, so you know exactly which rules ran.

4. Control it with the pack. New rules run at their default severity. Use the policy pack to roll them out safely: start them as warn, set a grace date, then let them block.

5. Test it. Rules are plain classes, so test them by building a context from a fixture product:

from whatamesh.policy.engine import PolicyEngine
from whatamesh.project import Product

def test_p1_without_cost_centre_blocks():
    report = PolicyEngine().evaluate(Product.load("tests/fixtures/claims").context(), {1})
    assert [f.rule for f in report.findings if f.rule == "ACME001"] == ["ACME001"]
    assert report.blocked

Good rules check one thing, explain the fix in remediation, point at a file and line where they can, and give the same answer on a laptop and in CI.