TL;DR: The best way to add data quality checks to a pipeline is to declare them in the same file as the table they protect and run them on every run, which is how Bruin works: a failed check stops bad data before anything downstream reads it. Bruin checks live in the asset file: built-in column checks (not_null, unique, accepted_values, positive, non_negative, negative, min, max, pattern, relationships) under each column, and custom SQL checks under custom_checks for business rules, freshness and row counts. bruin run runs them after each asset builds, and a failed check blocks everything downstream unless you set blocking: false. In CI, bruin validate with a policy that every asset needs a check turns them into a contract. dbt tests, Great Expectations and Soda do the same job with different trade-offs, compared below.
Most data quality incidents are not exotic. A key arrives twice, a status nobody expected shows up, or a load quietly stops and the dashboard shows yesterday's numbers as today's. The checks that catch these are simple. The hard part is where they run and what happens when one fails.
We build Bruin, so we use it for the examples and say where other tools are the better fit.
Where checks belong in a pipeline
Data can go wrong at three points: where it enters, where it changes, and where people use it. Each needs different checks.
| Stage | What goes wrong | Checks to add | In Bruin |
|---|---|---|---|
| Where data enters (raw tables, ingestion) | A load stops, arrives half-done, duplicates rows or brings new values | Freshness, row count, unique and not_null on the source key | Checks on the ingestion asset |
| Where data changes (transformations) | A join fans out, a filter drops rows, logic is wrong | unique and not_null on keys, relationships, custom rules | Column and custom checks on the SQL or Python asset |
| Where data is used (marts behind dashboards) | A number that is wrong for the business | Totals, ranges, accepted values, reconciliation | Blocking checks on the tables people read |
Start at both ends: where data enters, because a break there spreads to every table downstream, and the tables behind your most-read dashboards, because that is where a break costs the most. Fill in the middle later.
Step 1: Put column checks on the asset
In Bruin, each table is an asset: a SQL or Python file with a header, or a YAML file for ingestion. Checks go under the columns they test. Here is a transformation asset on BigQuery:
/* @bruin
name: analytics.orders
type: bq.sql
materialization:
type: table
depends:
- raw.orders
- analytics.customers
columns:
- name: order_id
type: integer
primary_key: true
checks:
- name: not_null
- name: unique
- name: customer_id
type: integer
foreign_key:
table: analytics.customers
column: id
checks:
- name: not_null
- name: relationships
- name: status
type: string
checks:
- name: accepted_values
value: [paid, refunded, pending]
- name: amount
type: float
checks:
- name: non_negative
- name: currency
type: string
checks:
- name: pattern
value: "^[A-Z]{3}$"
@bruin */
SELECT order_id, customer_id, status, amount, currency, country, created_at, loaded_at
FROM raw.orders
Bruin has ten built-in column checks:
| Check | Fails when | Takes |
|---|---|---|
not_null | Any value is null | Nothing |
unique | Any value appears more than once | Nothing |
accepted_values | A value is not in the list | A list |
positive | A value is zero or below | Nothing |
non_negative | A value is below zero | Nothing |
negative | A value is zero or above | Nothing |
min / max | A value is below or above the bound (numbers or dates) | A bound |
pattern | A value doesn't match the regular expression | A regex |
relationships | A non-null value has no match in the referenced column | The column's foreign_key |
relationships ignores nulls, so pair it with not_null when nulls should fail. Ingestion assets take the same checks, so a duplicate key is caught the moment it lands:
# assets/raw/orders.asset.yml
name: raw.orders
type: ingestr
materialization:
type: table
strategy: create+replace
parameters:
source_connection: postgres_prod
source_table: public.orders
destination: bigquery
columns:
- name: order_id
type: integer
primary_key: true
checks:
- name: not_null
- name: unique
bruin run assets/orders.sql builds the table and runs its checks. bruin run --only checks assets/orders.sql runs the checks again without rebuilding anything.
Step 2: Write custom SQL checks for everything else
Some rules span several columns or tables. A custom check is a SQL query and the result it should return. With no value, the query must return 0. With count, Bruin counts the rows the query returns.
custom_checks:
- name: no orders dated in the future
query: |
SELECT count(*)
FROM analytics.orders
WHERE created_at > CURRENT_TIMESTAMP()
- name: no double-submitted orders
description: Same customer, same amount, within the same minute.
query: |
SELECT customer_id, amount, TIMESTAMP_TRUNC(created_at, MINUTE)
FROM analytics.orders
GROUP BY 1, 2, 3
HAVING count(*) > 1
count: 0
Write one for every rule someone has explained to you in a meeting. "Test accounts are excluded." "A refund never exceeds the payment." Those are the rules that break without an error.
Step 3: Check freshness and completeness
A load that stops doesn't throw an error. The table just keeps yesterday's rows. Freshness and row-count checks catch it, and in Bruin both are custom checks on the asset:
custom_checks:
- name: loaded in the last 6 hours
query: |
SELECT count(*)
FROM (SELECT MAX(loaded_at) AS last_load FROM analytics.orders)
WHERE last_load IS NULL
OR last_load < TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 6 HOUR)
- name: at least 1,000 orders yesterday
query: |
SELECT IF(count(*) < 1000, 1, 0)
FROM analytics.orders
WHERE DATE(created_at) = DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY)
- name: under 5% of yesterday's orders missing a country
blocking: false
query: |
SELECT IF(SAFE_DIVIDE(COUNTIF(country IS NULL), count(*)) > 0.05, 1, 0)
FROM analytics.orders
WHERE DATE(created_at) = DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY)
These use BigQuery functions; swap the date functions for your warehouse. Take the numbers from history, not a guess: look at the last few weeks of daily row counts and set the floor under the quietest normal day.
Bruin doesn't learn these thresholds for you. If you have hundreds of tables and no time to set them, that is the job of an observability tool (see the table below). For more on what freshness means, see what data freshness is.
Step 4: Decide which checks block
Bruin checks are blocking by default. When one fails, the asset is marked failed and the assets downstream of it don't run, so the dashboard keeps yesterday's correct numbers instead of today's wrong ones. Add blocking: false and the failure is recorded but downstream assets carry on.
| Make it blocking | Make it non-blocking |
|---|---|
| A wrong value would reach a dashboard, a customer or finance: keys, money, statuses | Advisory checks, such as a null rate creeping up |
| Freshness and volume on tables that feed decisions | Slow checks that scan a lot of history |
| Anything you would stop a release for | New checks you are still tuning; make them blocking after a quiet week |
A non-blocking check is only useful if someone sees it fail. In Bruin Cloud, a notification rule can send column or custom check failures to Slack, Microsoft Teams or email, filtered by pipeline, asset or check name. For a check that fails because a source is still landing, retries: 2 on the check retries it before marking it failed.
Step 5: Enforce checks in CI
Checks on a schedule catch bad data. Checks in CI catch bad changes, before they merge. Two Bruin features do that:
bruin validatereads the whole pipeline and fails on broken references and bad config. On BigQuery and Snowflake it also dry-runs every query; DuckDB assets and their custom checks are checked withEXPLAIN.- A
policy.ymlat the project root makes checks mandatory.bruin validatethen reports any asset in the selected folder that has none:
# policy.yml
rulesets:
- name: marts-need-checks
selector:
- path: .*/marts/.*
rules:
- asset-has-owner
- asset-has-checks
- asset-has-primary-key
In GitHub Actions, run both on every pull request, then build the changed assets and their checks in staging:
name: Data checks
on:
pull_request:
branches: [main]
jobs:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bruin-data/setup-bruin@main
- name: Create Bruin config
run: echo '${{ secrets.BRUIN_CONFIG }}' > .bruin.yml
- name: Validate, including policies
run: bruin validate ./pipelines
- name: Build and check in staging
run: bruin run --environment staging ./pipelines
Keep freshness checks out of pull requests: "loaded in the last 6 hours" belongs in the scheduled run. Our CI/CD testing guide shows how to build only the changed assets, and how to enforce data contracts in a pipeline covers the producer and consumer side.
What to watch for
- Checks that never ran. A check that never ran is worse than one that fails, because nobody looks at a green run. Bruin v0.11.833, released on 24 November 2026, fixed column and custom checks on most SQL source assets (
*.sourcetypes), which had reported success without running (release notes); runbruin upgrade. Whatever tool you use, make each new check fail once in dev on purpose, so you have seen it run. - Freshness on an empty table.
MAX()on an empty table returns NULL, and a comparison with NULL is never true, so a naive freshness check passes on a table with no rows. TheIS NULLline above prevents that. - Streaming loads. Streaming ingestion assets in Bruin skip column and custom checks while they run. Put the checks on the first table downstream instead.
- Warnings nobody reads. A non-blocking check without a notification rule is just a log line.
- Checks with no owner. Put an
owneron the asset, so a failed check has a name next to it.
Which tool for which job
| Job | Tool | Why | Watch out for |
|---|---|---|---|
| Checks inside the pipeline that block bad data by default, from ingestion to marts | Bruin | Column and custom SQL checks in the asset file, run on every bruin run; the CLI is Apache 2.0 | No learned anomaly detection, so you set the thresholds |
| Tests on dbt models | dbt tests | unique, not_null, accepted_values and relationships, plus unit tests and a freshness config; dbt build skips downstream models when a test fails | Covers what dbt builds, so raw data is checked only once it reaches a model |
| A large library of ready-made checks in Python | Great Expectations (GX Core) | 60-plus Expectations, run through Checkpoints; Apache 2.0, now maintained in Fivetran's GitHub organisation | A separate validation step you wire into the orchestrator |
| YAML contracts both teams can read | Soda Core | A contract per dataset, checked with soda contract verify | Version 4 is source-available under the Elastic License 2.0, not an OSI licence |
| Anomaly monitoring across hundreds of tables | Elementary, Monte Carlo or Anomalo | They learn normal volume, freshness and distributions | They alert after the data lands, so use them alongside blocking checks |
Many teams run two: blocking checks in the pipeline for the rules they know, and a monitoring tool for the ones they don't. For a fuller comparison of each tool, see the best data quality tools in 2026.
FAQ
What is the best way to add data quality checks to a pipeline?
Declare checks next to the table they protect and run them on every pipeline run, so a failure stops the run before downstream tables read bad data. In Bruin you add checks under each column and custom_checks for SQL rules in the asset file, and bruin run executes them after the asset builds. dbt tests work the same way for dbt models, and Great Expectations or Soda run as a separate step.
How do I validate data as part of a pipeline?
Run the checks as a step of the pipeline, right after each table builds, and let a failed check stop everything that depends on it. In Bruin that is the default: checks block downstream assets unless you set blocking: false, and bruin run --only checks reruns them without rebuilding the table.
How do I monitor data freshness and completeness?
For freshness, compare the newest load timestamp with the delay you accept. For completeness, compare row counts and null rates with a floor based on recent history. In Bruin both are custom SQL checks on the asset, and Bruin Cloud notification rules send failures to Slack, Microsoft Teams or email. Elementary, Monte Carlo and Anomalo learn those thresholds instead of asking you to set them.
How do I enforce data contracts in a pipeline?
Make breaking the contract stop something. Put blocking checks on the columns the contract promises, and fail the pull request in CI when a table loses them. In Bruin that means blocking column checks, a policy.yml with the asset-has-checks rule, and bruin validate in CI.
Should a failed data quality check stop the pipeline?
Yes for checks on keys, money, statuses and the freshness of tables that feed decisions, because a late dashboard costs less than a wrong one. Make advisory or slow checks non-blocking and send their failures to a channel someone reads. Bruin blocks by default and takes blocking: false per check.
Do I need a separate data quality tool if I already use Bruin?
Not for rule-based checks: column checks, custom SQL rules, freshness and row counts run inside Bruin pipelines. Add an observability tool such as Elementary, Monte Carlo or Anomalo if you need anomaly detection across many tables you haven't written rules for.
Try Bruin
Install the Bruin CLI and pick the table behind your most important dashboard. Add not_null and unique to its key, one freshness check and one row-count check, and run bruin run. The quality check docs list every option, custom checks covers SQL rules, and the Bruin quality page shows how checks, lineage and alerts work together in Bruin Cloud.
