Skip to main content
Contracts are split across four directories, each validated against its own Pydantic model at load time. See Contracts & guardrails for the concepts behind these fields.
DirectoryModelLoaded by
contracts/metrics/*.yamlMetricBindingload_metric_bindings
contracts/guardrails/*.yaml (excluding finality-*.yaml)Guardrailload_guardrails
contracts/guardrails/finality-*.yamlFinalityRuleload_finality
contracts/assertions/*.yamlAssertionload_assertions
A finality rule is filename-discriminated from a guardrail — both live under contracts/guardrails/, but only files named finality-*.yaml load as FinalityRule; everything else in that directory loads as Guardrail.

contracts/metrics/*.yamlMetricBinding

metric: revenue
owner: "@data-platform"
canonical:
  kind: single
  source: orders
  measure: total_revenue
provenance: human_curated
aliases: ["net revenue", "rev"]
status: active
FieldTypeDefaultGoverns
metricstrn/a (required)The logical metric name the binding resolves.
ownerstr | nullnullTeam/person accountable for the definition.
canonicalCanonicalRefn/a (required)The compilation strategy and its parameters; see below.
provenanceProvenancehuman_curatedboard_approved | human_curated | inferred.
labelstr | nullnullHuman-readable display name.
aliaseslist[str][]Alternate names resolving to this binding (must not duplicate metric itself).
deprecated_alternativeslist[DeprecatedAlternative][]Known non-canonical definitions, explicitly flagged as superseded.
exampleslist[Example][]Usage-backed example queries (from assertions, observed queries, or usage evidence).
statusStatusactiveactive | deprecated. Only active bindings are checked for duplicate names/aliases across the project.
Ambiguity rule: if a requested name matches zero or more than one active binding, the compiler returns a structured AMBIGUOUS/UNRESOLVED error rather than guessing.

canonical (CanonicalRef) — one shape per kind

kind selects a compilation strategy; each kind requires a different subset of fields (validated at load time — missing a required field for the chosen kind raises a located error):
kindRequired fieldsCompiles as
single (default)source, measureResolve to one (source, measure) pair.
rationumerator, denominator (metric names)Aggregate numerator & denominator independently, divide after.
weighted_avgweighted_sum, weight (metric names)Weighted-sum ÷ weight.
semi_additivesource, measure, collapse_dimension, collapse_aggSum over every dimension except collapse_dimension, which collapses via collapse_agg.
distinct_countsource, distinct_on (column name)Recompute count(distinct …) at the requested grain.
percentilesource, column, quantile ∈ (0, 1)Recompute the quantile at the requested grain from base rows.
opaquesource, measure, native_grain (non-empty list of dimension columns)Serve only at its declared native grain; any other grain returns UNSUPPORTED_MEASURE.
Full field list on CanonicalRef:
FieldTypeDefaultUsed by
kindBindingKindsingleAll.
sourcestr | nullnullsingle, semi_additive, distinct_count, percentile, opaque.
measurestr | nullnullsingle, semi_additive, opaque.
numerator / denominatorstr | nullnullratio (both are metric names).
weighted_sum / weightstr | nullnullweighted_avg (both are metric names).
on_zero_denominatorOnZeroDenominatornull (coerced)ratio/weighted_avg: null | zero | error when the denominator is zero.
collapse_dimensionstr | nullnullsemi_additive: the dimension that collapses (typically time).
collapse_aggCollapseAgg | nullnullsemi_additive: last | first | avg | min | max.
distinct_onstr | nullnulldistinct_count: column to count distinct values of.
columnstr | nullnullpercentile: column the quantile is computed over.
quantilefloat | nullnullpercentile: value in (0, 1).
native_grainlist[str] | nullnullopaque: dimension columns the metric is pre-aggregated to.
population_filterstr | nullnullAll kinds: SQL predicate AND-ed into every leaf query’s WHERE before aggregation, defining the population the metric is about (e.g. excluding test accounts).

deprecated_alternatives[] (DeprecatedAlternative)

FieldTypeDefaultGoverns
sourcestrn/a (required)The superseded source.
refstrn/a (required)The superseded measure/column reference.
reasonstrn/a (required)Why it was superseded.

examples[] (Example)

FieldTypeDefaultGoverns
queryExampleQueryn/a (required){ metrics: list[str], dimensions: list[str] = [], filters: list[str] = [] }.
originstrn/a (required)Typed discriminator: observed_query, assertion:<id>, or usage_evidence:<id>.
frequencyint | nullnullObserved count, when available (omitted for assertion-sourced examples).

contracts/guardrails/*.yamlGuardrail

id: revenue-excludes-refunds
applies_to: { source: orders, measure: total_revenue }
kind: mandatory_filter
filter: "status != 'refunded'"
severity: error
rationale: "Refunds are reversals, not revenue."
FieldTypeDefaultGoverns
idstrn/a (required)Guardrail identifier.
applies_toAppliesTon/a (required)Target: { source, measure } or { metric } — exactly one shape, never both or neither.
kindGuardrailKindn/a (required)mandatory_filter | required_dimension | restrict_source; see below.
filterstr | nullnullRequired (non-empty) when kind: mandatory_filter.
restrict_toRestrictTo | nullnullRequired when kind: restrict_source; { role: "final" | "provisional" }.
contextstr | nullnullRequired (non-empty) when kind: restrict_source — the named context the restriction applies in (e.g. board_reporting).
severitySeverityerrorerror blocks the query; warn annotates the result without blocking it.
rationalestrn/a (required)Why the rule exists — surfaced to the caller.
phasestr | nullnullOptional compiler-pipeline phase hint.
kindBehaviorStatus
mandatory_filterThe predicate is always AND-ed into the compiled WHERE.Enforced
restrict_sourceIn a given context, only the source matching restrict_to.role is permitted.Enforced
required_dimensionThe query must group by or filter on a given dimension or be rejected.Declarable in the schema; not yet enforced by the compiler

contracts/guardrails/finality-*.yamlFinalityRule

metric: revenue
realizations:
  - { source: orders,    role: final,       watermark: "business_day - 1 day" }
  - { source: orders_rt, role: provisional }
coalescing: "window <= watermark ? final : provisional"
result_flag: per_row
board_only_final: true
FieldTypeDefaultGoverns
metricstrn/a (required)The metric these realizations apply to.
realizationslist[Realization][]Physical sources along the freshness axis; see below.
coalescingstr | nullnullExpression selecting which realization backs a given time window.
result_flagstr | nullnullHow the final/provisional tag is attached to results (e.g. per_row).
board_only_finalboolfalsePairs with a restrict_source guardrail so a restricted context sees only the final source.

realizations[] (Realization)

FieldTypeDefaultGoverns
sourcestrn/a (required)The semantic source backing this realization.
rolestrn/a (required)"final" or "provisional".
watermarkstr | nullnullCutoff expression for this realization.
tzstr | nullnullTimezone the watermark is evaluated in.

contracts/assertions/*.yamlAssertion

id: revenue-2025-q1
query: { metrics: [revenue], filters: ["order_date in 2025-Q1"] }
expect: { rows: 1, values: { revenue: 4218334.10 }, tolerance: 0.01 }
source_of_truth: "Finance close, FY25 Q1"
FieldTypeDefaultGoverns
idstrn/a (required)Assertion identifier.
querydict[str, Any]n/a (required)A semantic query (metrics, dimensions, filters) run through the compiler.
expectAssertionExpect{}Expected result; see below.
source_of_truthstr | nullnullWhere the expected value came from (e.g. a finance close).

expect (AssertionExpect)

FieldTypeDefaultGoverns
rowsint | nullnullExpected row count.
valuesdict[str, Any]{}Expected value per output column.
tolerancefloat | nullnullRelative tolerance for numeric comparison (e.g. 0.01 = 1%); null means exact match.
canonic assert runs every assertion through the compiler and gates on the result; canonic query --harness runs matching assertions inline against a single query.