0. Decision and Data Foundations

Data Contracts

Make row grain, keys, timestamps, lineage and measurement assumptions explicit

Data Contracts

One row must mean one thing

HarborMart stores three different grains:

TableOne rowCandidate key
ordersone orderorder_id
order_linesone product line within an orderorder_id, product_id
delivery_eventsone status eventorder_id, event_time, event_type

Joining orders to order_lines multiplies order rows. Summing order_value after that join double-counts orders with several lines.

Small example

orderorder valuelines
A£303
B£201

The true total is £50. After a line-level join, summing repeated order values gives 3(30)+1(20)=£1103(30)+1(20)=£110. The arithmetic is correct; the grain is wrong.

The five-clock audit

For every field, record:

ClockMeaningExample
event timewhen the world changedorder placed 17:03
observed timewhen the system captured itpayment event 17:03:04
available timewhen a decision service could use itfeature store 17:04
decision timewhen action was selectedpromise confirmed 17:03:10
label timewhen the outcome became knowabledelivery completed 19:42

A feature is valid only if its available time is no later than decision time. A final route duration entered after delivery is not a predictive feature for checkout, even if its event date is the same day.

A minimum data contract

FieldRequired statement
populationall eligible UK delivery orders accepted in completed weeks
exclusionstest accounts and documented outages; cancellations retained as a separate outcome
unitone accepted order
keystable unique order_id
targetdelivered after promised end timestamp
feature cutoffcheckout confirmation time
timezoneEurope/London with daylight-saving handling
currencyGBP gross or net of VAT, stated consistently
missingnessvalid absence, delayed record or system failure distinguished
revision policywhich late-arriving events restate historical metrics

Missing is a process observation

Do not begin with mean imputation. Ask why the value is absent:

  • structural: apartment floor does not apply to a house;
  • random capture failure: scanner briefly offline;
  • selective: difficult deliveries omit a completion code more often;
  • not yet available: outcome still developing.

An indicator plus domain review may be more honest than replacing every blank with an average. If missingness depends on the unobserved value, routine imputation can preserve bias while making the table look complete.

Join checks that must balance

Before and after each join, record:

  1. row count and distinct key count;
  2. unmatched keys on each side;
  3. duplication factor by key;
  4. totals that should be invariant;
  5. distribution of newly missing fields.

For the £50 example, sum(order_value) is an invariant only at order grain. At line grain, allocate value or aggregate lines before joining.

Data lineage in one sentence

late_flag is computed nightly from immutable promise timestamps and the first valid delivered event, with source-system version, extraction time and transformation code recorded.

This sentence identifies source, rule, timing and reproducibility. “From the warehouse” does not.

Quick check

Why is a customer’s current lifetime order count dangerous in a historical churn-training row?

Answer
The current count includes orders placed after the historical decision date. Reconstruct the count as of that date; otherwise future behaviour leaks into the feature.

Further evidence

The dataset-documentation literature treats provenance and intended use as part of the data object, not optional prose. Start with Datasheets for Datasets and adapt its questions to the decision context.

Next: Reproducible Workflow

Copyright © 2026