Tests, freshness, and data quality
Declare column-level tests and source freshness contracts in YAML, then run them from the Data Quality UI or the REST API.
Tests, freshness, and data quality
A test is an assertion you write in YAML about your data. Goni compiles it to a query against your warehouse, runs it on a schedule (or on demand), and records the outcome as pass, fail, or error (with unknown reserved for tests that have never run yet). A freshness contract is a special kind of test that asks a different question: not “is this column clean?” but “is this source table current enough to trust?”
Together the two surfaces answer whether today’s numbers are safe to quote.
You’ll learn:
- How to author schema tests on models and sources.
- The built-in test kinds (
not_null,unique,accepted_values,row_count_min,row_count_max,freshness,custom_sql).- How to declare per-source freshness SLAs with
warn_afteranderror_after.- Where results show up: the Data Quality panel, the audit log, and the trust signal in AI Q&A.
Schema tests
Tests attach to columns, either on a model (something you built in the semantic layer) or on a source table (something a connector loaded). All column-level tests live in a single tests.yml at the project root. Seven test kinds ship out of the box.
# tests.yml - model column tests
version: 2
models:
- name: dim_customers
description: One row per customer, deduplicated.
columns:
- name: customer_id
tests: [not_null, unique]
- name: email
tests: [not_null]
- name: plan_tier
tests:
- accepted_values:
values: [free, starter, growth, enterprise]
- name: signup_country
tests:
- accepted_values:
values: [US, GB, DE, FR, LT, PL]
severity: warn
The same shape works for sources, so you can catch problems the moment raw data lands, before your models even run:
# tests.yml - source column tests
version: 2
sources:
- name: billing
tables:
- name: subscriptions
columns:
- name: id
tests: [not_null]
- name: status
tests:
- accepted_values:
values: [active, past_due, cancelled, paused]
Test kinds
| Kind | What it asserts | Notes |
|---|---|---|
not_null | No NULL values in the column. | Cheapest test. Run it on every primary key and every column your metrics depend on. |
unique | Every non-null value appears at most once. | Runs a group-by-and-count under the hood. Safe on modelled dimensions; avoid on raw ingestion tables that may hold multiple versions of the same row before dedup. |
accepted_values | Every non-null value is in a given list. | NULL is allowed. Add a separate not_null if you also require the value to be present. |
row_count_min | The table has at least N rows. | Catches empty landings and truncated loads. Configure the floor with min_rows. |
row_count_max | The table has at most N rows. | Guardrail against runaway backfills or duplicated ingests. Configure the ceiling with max_rows. |
freshness | The newest row is younger than a maximum age. | Attaches to a column (typically the ingestion timestamp) and takes max_age_minutes. Overlaps with the source-level freshness contract below; use whichever surface fits your workflow. |
custom_sql | A caller-supplied SQL query returns zero rows. | Escape hatch for assertions the built-in kinds cannot express (cross-column invariants, referential integrity, business rules). Requires allow_admin_policies to author because the SQL runs verbatim against the warehouse - see Data quality governance. |
Each entry may take an optional severity: warn (default is error) as authoring metadata. The current runner still marks the outcome as pass, fail, or error regardless of severity; the field is preserved end-to-end so you can filter on it in the UI and future releases can wire it into alert routing.
# tests.yml - row-count and freshness at the model or source level
version: 2
sources:
- name: billing
tables:
- name: subscriptions
tests:
- row_count_min:
min_rows: 1000
- row_count_max:
max_rows: 5000000
columns:
- name: _goni_ingested_at
tests:
- freshness:
max_age_minutes: 60
# tests.yml - a custom_sql escape hatch
version: 2
models:
- name: fct_subscriptions
tests:
- custom_sql:
name: arr_never_negative
sql: |
SELECT customer_id, arr_eur
FROM {{ ref('fct_subscriptions') }}
WHERE arr_eur < 0
Source freshness
Freshness answers “how stale is this table’s newest row?” Declare it on the source in sources.yml, alongside a loaded_at_field (the column Goni takes max() of to measure age):
# sources.yml
sources:
- name: billing
schema: raw
tables:
- name: subscriptions
loaded_at_field: _goni_ingested_at
freshness:
warn_after: { count: 1, period: hour }
error_after: { count: 6, period: hour }
- name: invoices
loaded_at_field: paid_at
freshness:
warn_after: { count: 12, period: hour }
error_after: { count: 36, period: hour }
period accepts minute, hour, day, or week. The evaluation ladder is straightforward: if the newest row is older than error_after, the source contract fails with a stale-source reason; if it is older than warn_after but younger than error_after, the run still records pass and the warn threshold surfaces as a soft signal in the panel; otherwise the run records pass. A source with no loaded_at_field cannot be freshness-tested, and Goni will tell you so in the Data Quality panel rather than silently pass.
Prefer an ingestion timestamp (a column your Goni pipeline adds when it lands the row, such as _goni_ingested_at) over a source-authored updated_at. The pipeline column measures pipeline health; the source column can drift if the source system pauses.
Running tests
You have three ways to trigger a run:
- Data Quality panel. Open Data Quality in the app. You get a per-table roll-up (
pass,fail,error,unknown) and a recent-runs feed. Hit Run all for a full sweep, or drill into a single table and hit Run tests to scope it. - REST API.
POST /api/data_quality/run_allruns the full sweep, andPOST /api/data_quality/{table}/runscopes to one table.GET /api/data_quality/testslists the current test inventory, andGET /api/data_quality/results?limit=50returns the recent-runs feed. - Automatic schedule. Goni sweeps tests in the background at the cadence set by process environment variables (default: hourly for green tests, more often for tests that just failed). Freshness is checked on the same clock.
Where results show up
- Data Quality panel. The primary surface. Each table shows its tests, the last outcome, when it last ran, and rows failed on the current failure.
- Notifications on pass -> fail transition. When a scheduled sweep flips a test from
passtofail, Goni posts a Slack-shaped payload toGONI_DQ_ALERT_WEBHOOK_URL(with an optional HMAC signature whenGONI_DQ_ALERT_WEBHOOK_SECRETis set). Tests declared withseverity: warnsuppress the fan-out; the transition is still logged for triage. See Data quality governance. - Audit log. Every run, every author change, and every scheduled sweep records an event under the
data_quality.*family (run_table,run_all,put_test,delete_test,profile). See Audit and lineage for the log schema. - Trust overlay on dashboard metrics. A metric tile’s trust panel shows the compiled SQL, its lineage, the latest test results for the models behind it and the last ingestion time of its sources, so a failing test or a stale source is visible right where the number is read.
- AI Q&A grounding (coming soon). When someone asks a question that resolves to a metric, and that metric depends on a model with a currently-failing test or a source past its
error_afterwindow, the AI answer carries a trust warning and the chart flags as untrusted. This keeps stale numbers from being quoted as fact.
Wiring a failing test into an alert
DQ notifications are handled by the data-quality subsystem, not by the general alert engine. On every sweep, when a test flips from pass to fail (severity warn suppressed), Goni fans the transition out to the Slack-shaped webhook you configure in GONI_DQ_ALERT_WEBHOOK_URL. See Data quality governance for the full posture.
The general alert engine (/docs/operate/alerts-and-reports) targets numeric metrics crossing thresholds, not test outcomes. Alerts require a semantic-layer metric name (not arbitrary SQL), so there is no “count failing tests” workaround you can wire without first shipping a canonical dq_failing_tests metric in the semantic project. Reserve alerts for value-driven signals like “MRR dropped 10% week-over-week”.
Related
- Sources and models - where
loaded_at_fieldand columns are declared. - Data quality governance - RBAC, custom_sql authorship, and audit coverage.
- Alerts and scheduled reports - metric-threshold alerts (distinct from DQ notifications).
- REST API - full endpoint reference.
- Access control - who can run tests and who can edit them.
Last updated