Data Quality Assertions

Assertions are Evaluate Expression steps that test your data after it's been created or updated. If the assertion fails, a notification is sent to the team. This acts as an automated data quality gate.

How Assertions Work

An assertion step has three components:

  1. A SQL query that checks for violations (returns a count)
  2. An evaluate expression that interprets the result as pass/fail
  3. Notifications configured to fire on On False expression (assertion failed)

Uniqueness Assertion

The most common assertion — verifies that a primary key column has no duplicates.

-- Step SQL
WITH counting AS (
  SELECT
    COUNT(*) AS all_rows,
    COUNT(DISTINCT(company_id)) AS primary_key
  FROM datamarts.my_table
)

SELECT
  CASE WHEN all_rows = primary_key
  THEN TRUE ELSE FALSE END AS uniqueness
FROM counting

Evaluate expression:

{{ $response.uniqueness == 1 }}

Non-Null Assertion

Verifies that required columns never contain NULL values.

SELECT COUNT(*) AS null_count
FROM core.my_table
WHERE FALSE
  OR db_row_timestamp IS NULL
  OR tenant IS NULL
  OR user_id IS NULL

Evaluate expression:

{{ $response.null_count == 0 }}

The WHERE FALSE OR ... pattern is a clean way to list all the columns that must not be null.

Freshness Assertion

Verifies that the most recent data is from today, catching stale pipelines.

WITH maximum AS (
  SELECT MAX(db_row_timestamp) AS max_db_row_timestamp
  FROM datamarts.my_table
)

SELECT
  DATE(max_db_row_timestamp) = CURRENT_DATE AS date_evaluation
FROM maximum

Evaluate expression:

{{ $response.date_evaluation == 1 }}

Freshness Variant: Has Today's Entries

Check that new rows were imported today (useful for incremental loads):

WITH counting AS (
  SELECT
    MAX(DATE(imported_at)) AS max_value,
    CURRENT_DATE() AS current_value
  FROM my_schema.my_imported_table
)

SELECT
  CASE WHEN max_value = current_value
  THEN TRUE ELSE FALSE END AS has_todays_entries
FROM counting

Notification Setup

On assertion steps, configure notifications to trigger on On False expression (not On Error):

Setting Value
Trigger On False expression
Notify via Email
Title My Table: Assertion FAILED "uniqueness"
Body {{ $log_html }}

Also add an On Error notification in case the assertion query itself fails.

Chaining Assertions

You can chain multiple assertions using Next step on true/false logic:

  1. Assertion: uniqueness → Next step on true/false → jump to "Assertion: non-null"
  2. Assertion: non-null → Next step on true/false → Stop

This way all assertions run regardless of individual results, and each one sends its own notification if it fails.

Cross-Environment Assertions

When running assertions across multiple environments (staging, production), see Cross-Environment Workflows for patterns that generate dynamic assertions using STRING_AGG + FORMAT to check all environments in a single query.

Tips

  • Always put assertions after the table creation step
  • Use the On False expression trigger (not On Error) for assertion notifications
  • Include {{ $log_html }} in the notification body for debugging context
  • Tag assertion steps with a clear name like "Assertion: uniqueness" for easy identification in logs