Skip to content

Data checks

Create checks.py in the project root. Select models by metadata and yield checks with ordinary Python loops, conditions, and imported helpers:

from datetime import timedelta
from selectjoin import freshness
def build(project):
for model in project.models(layer="staging"):
yield freshness(model, column="updated_at", max_age=timedelta(hours=24))

Every staging model gets a named check such as stg_orders.freshness. Model metadata includes name, layer, grain, and dependencies, so a policy can skip models or vary thresholds and columns.

Terminal window
selectjoin checks --layer staging
selectjoin compile-checks --layer staging --output target/checks
selectjoin compile-checks stg_orders.freshness --dialect postgres

Each check compiles to a standalone SELECT, including its upstream model queries. Zero rows means success when the SQL is eventually run.

Freshness uses MAX(column). A missing timestamp (empty or all-null input) or one older than the threshold produces one failure row. Exactly the threshold passes; future timestamps pass. Thresholds must be positive whole seconds. Use a timestamp column compatible with the database’s current time and timezone.

Yield Check(name, model_name, query, description) with a query that returns failure rows. Use Context(...).ref() for model references. Raw tables and write queries are rejected. Reusable check factories can live in components/ and be imported from checks.py.

selectjoin check validates and compiles definitions; it never tests data.