view source

Metric Definitions: Specs, Metric Trees and Guardrails

skill

Define metrics so two people get one number: formula, grain, filters, owner, metric tree, guardrails, ratio pitfalls. Use when writing metric specs.

Apache-2.0 Any text or YAML editor. The dbt semantic layer examples need a dbt project with MetricFlow.

agents that use this skill

instructions

Overview

A metric is a promise that anyone who computes it from the same data gets the same number. Most disagreements ("marketing says 4.1%, finance says 3.8%") come from a missing piece of the definition, not from a bug. This skill writes a metric specification complete enough to compute from, arranges metrics into a tree, pairs each goal with guardrails, and records changes. The deliverable is a specification a second person can implement independently and check by matching numbers.

Mental model

  • A definition is a computation plus its scope. The scope is the grain, the filters and the time window; leaving one out is how two correct computations disagree.
  • Metrics form a tree. Amazon's weekly business review method separates output metrics, which the business ultimately cares about (revenue, free cash flow), from controllable input metrics, which are actions teams can drive and believe move an output. An output in one area can be an input for another.
  • A goal metric is optimized and guardrail metrics are watched. Kohavi, Tang and Xu describe guardrail metrics as critical metrics designed to alert about violated assumptions, of two types: organizational (protect the business) and trust-related (protect the validity of the measurement).
  • Any metric that becomes a target gets pushed on. The defense is to define what must not get worse in the same document.

Rules

Write the specification

One entry per metric. A field left empty is a defect, not an optional extra.

FieldWhat it holdsFailure it prevents
NameOne name, lowercase with underscores, never reusedTwo metrics under one name
Plain definitionOne sentence a non-analyst can repeatA formula nobody can explain
FormulaNumerator and denominator, each with its own filter and unitDifferent treatment of the numerator and denominator
GrainThe unit of one row: user, order, session, account-dayFan-out joins, double counting
FiltersInclusions and exclusions, written as rules (test accounts out, refunds in)Hidden exclusions
Time windowThe date field used, the time zone, the period boundaries, the lookbackTwo dates for one event
SourceTable or system of record and the query or model that computes itComputing from a copy
OwnerA person or team who approves changesOrphaned definitions
ConsumersThe dashboards, reports and teams that read itA change nobody was told about
RefreshHow often it updates and its expected lagReading a half-loaded period
CaveatsKnown gaps, restatement rules, edge casesSurprise at review time
Version and dateCurrent version and what changedSilent redefinition

When a definition has a unit, state it: percent as a fraction or as a number out of 100, currency and its rate date, durations in seconds or days.

Ratios: ratio of sums, not average of ratios

A ratio metric is computed by summing the numerator and the denominator over the full scope and then dividing, unless the specification says the unit of analysis is the group. Averaging per-group ratios weights every group equally, whatever its size.

Check: three days with (sessions, orders) of (100, 2), (1, 1) and (1, 1). The average of the daily conversion rates is 0.6733. The ratio of sums is 4 divided by 102, 0.0392. Both are legitimate numbers for different questions, so the definition names which one.

  • Name the denominator's population explicitly. "Conversion rate" over all sessions and over sessions that reached checkout are different metrics.
  • A ratio cannot be added across periods or segments. Store the numerator and the denominator, and divide at the last step.
  • A distinct count cannot be summed across groups either: a user active in two regions counts twice.

Build the metric tree

  1. Write the top metric: the one outcome the review is about, as a single output metric with a full specification.
  2. Break it into the inputs that mathematically or causally produce it. Revenue equals active customers times orders per customer times average order value is an identity; "marketing spend drives signups" is a hypothesis. Mark each edge as identity or hypothesis.
  3. Stop at inputs a team can act on this week. Every leaf needs an owner.
  4. Give each branch a specification as full as the top.
  5. Test hypotheses against history before a team is held to them. A branch that has not moved the parent in past data is a guess.

Amplitude's North Star playbook frames the same structure: a North Star Metric with related input metrics that connect the customer's needs, the product and the business.

Leading and lagging

A lagging metric reports an outcome after it happens (revenue, retention at day 90); a leading metric moves earlier and is expected to predict it. Whether a metric leads is a claim to test: show that it moves before the outcome, over enough history, before it replaces the outcome in a review. Report the lagging metric next to it until then.

Guardrails

  • For every goal metric, name at least one guardrail that would show the goal was reached by damaging something else: quality, cost, support load, a slower page, a higher refund rate.
  • Give each guardrail a threshold and an action: the change that triggers a review, and who is called.
  • For experiments, include the sample ratio mismatch check, which Kohavi, Tang and Xu say should be included for every experiment; it alerts that the split of users differs from the plan.
  • A target metric with no guardrail is incomplete. Expect it to be gamed, usually without bad intent: closing support tickets faster is met by closing them without solving them. Pair speed with a reopen rate.

Machine-readable format

dbt's semantic layer (MetricFlow) defines metrics in YAML. A metric requires a name and a type (simple, cumulative, derived, ratio or conversion); a simple metric requires an aggregation; a ratio metric requires a numerator and a denominator, each of which may carry its own filter and alias. Optional fields listed are description, label, config and filter. A metric name uses lowercase letters, numbers and underscores. A semantic model needs a time dimension column with a granularity and an agg_time_dimension, the default time dimension for its metrics. The latest spec (dbt v1.12 and later) puts numerator, denominator and the other type fields directly on the metric; the legacy spec nests them under type_params and defines simple metrics through measures, so match the project's version.

yaml
metrics:
  - name: checkout_conversion
    label: Checkout conversion
    description: "Orders divided by sessions"
    type: ratio
    numerator: orders
    denominator: sessions

Here orders and sessions are simple metrics defined in the same project. dbt can carry an owner in a metric's config meta or through a group; refresh and caveats have no field, so keep those in the written specification beside the file. When the user has no dbt project, write the specification as a table or a YAML file with the fields above; the format is a choice, the completeness is the rule.

Version a definition

  • A change that can move the number is a new version with a date, an author and a reason. Rename the metric when the meaning changes (active_users_v2), not when only the code changes.
  • Say what happens to history: recompute prior periods under the new version, or state the break.
  • Show old and new values for one overlapping period so the reader can see the size of the change.
  • Notify the consumers listed for the metric before the change goes live.

Examples

Vague to computable. Bad: "Active users: people who used the product recently." Good: "active_users_28d: distinct user_id with at least one event of type session_start in the last 28 days ending on the report date, UTC, internal accounts excluded. Grain: user. Source: the events table. Owner: product analytics. Refresh: daily by 06:00 UTC."

Average of ratios to ratio of sums. Bad: the dashboard averages each store's refund rate, so a store with 3 orders counts as much as one with 3,000. Good: total refunds divided by total orders across the stores, with the per-store rates shown beside it.

Lone target to guarded target. Bad: "Reduce average handle time." Good: reduce average handle time, with first-contact resolution held at or above its current level and a satisfaction score that must not fall by more than the agreed margin.

Checklist

  • Every field of the specification is filled for each metric, including owner and refresh.
  • Numerator and denominator are separately defined; ratios divide sums.
  • Two people computed it independently from the specification and the numbers matched; a mismatch means the specification is missing a piece.
  • The tree marks each edge as identity or hypothesis, and every leaf has an owner.
  • Each goal metric has a guardrail with a threshold and an action.
  • The version, the date, the reason and the treatment of history are recorded.
  • A dbt metric file, when one was written, was validated with the project's own tooling; otherwise say it was not run.

Composition / References

Scope limits: the statistics of an experiment, the layout of a dashboard, the warehouse model behind the metric and the review pack that reports it are separate jobs.