Model tests

A model test checks that a model's data is what you expect: a key column has no nulls or duplicates, a status column only holds known values, every order points at a customer that exists. Each test is a query that returns the rows breaking the rule. A test passes when that query returns no rows, or no more rows than you allow.

Tests use the same names and arguments as dbt's data_tests, including the common dbt_utils and dbt_expectations tests, so a test you know from dbt works the same way in Weld.

Open a model's tests

  1. Open the model in Transform.
  2. Click the Tests tab under the editor. The tab appears once the model is saved.

The tab lists the model's tests. Each row shows the test's type and column, its last result, when it should warn or fail (for example fails above 5 rows), and a short summary of its settings.

Add a test

  1. On the Tests tab, click Add test.
  2. Choose a test type. The types are grouped into Column tests, which check one column, and Model tests, which check the model as a whole. Hover over a type to see what it checks, and click Change to pick another one.
  3. For a column test, pick the Column.
  4. Fill in the type's settings. See Test types.
  5. Optionally set when the test should warn or fail, a row filter and a description. See Warn and fail thresholds.
  6. Click Add test.

You can also add a test from a query result: every column header shows the tests on that column, and clicking it opens Add test with that column filled in.

The columns you can pick follow the version you're testing. On Live you see the published model's columns. On Draft you see the columns of the editor's latest run, and columns that aren't published yet are marked Draft only. Run the draft to list a column you've just added.

Test types

Column tests

Testdbt namePasses whenSettings
Not nullnot_nullNo value in the column is null.
UniqueuniqueEvery value in the column appears once.
Accepted valuesaccepted_valuesEvery value is in a fixed list.values, and quote to compare the values as text. Values seen in the editor's latest result are offered as suggestions.
RelationshiprelationshipsEvery value exists in a column of another model or source table.to, the model or source table, and field, its column.
Accepted rangedbt_utils.accepted_rangeEvery value is between a minimum and a maximum.min_value, max_value (one or both), and inclusive.
Not empty stringdbt_utils.not_empty_stringNo value is an empty string.trim_whitespace also counts strings of only spaces as empty.
Not null proportiondbt_utils.not_null_proportionThe share of values that aren't null is within a range.at_least and at_most, between 0 and 1.
Matches patterndbt_expectations.expect_column_values_to_match_regexEvery value matches a regular expression.regex, and flags set to i to ignore case. A new test matches the pattern exactly as typed (is_raw).

Model tests

Testdbt namePasses whenSettings
Unique combination of columnsdbt_utils.unique_combination_of_columnsNo two rows share the same values in the chosen columns.combination_of_columns
Expression is truedbt_utils.expression_is_trueA SQL expression holds for every row, for example amount >= 0.expression
Equal row countdbt_utils.equal_rowcountThe model has as many rows as another model.compare_model
Recencydbt_utils.recencyThe newest timestamp in a column is within a recent window.field, the timestamp column, and interval and datepart, such as 1 day. ignore_time_component compares dates only.
Row count betweendbt_expectations.expect_table_row_count_to_be_betweenThe row count is between a minimum and a maximum.min_value, max_value (one or both), and strictly to exclude the bounds.
Custom SQLsingularYour query returns no rows.sql: a query that returns the failing rows. Write {{this}} for the model being tested.

A custom SQL test is a dbt singular test. For example, this test fails for every order with a negative amount:

select * from {{this}} where amount < 0

Warn and fail thresholds

A test counts the rows that break its rule. By default any failing row fails the test. You can change that on each test:

  • Severity: Error tests can fail; Warn tests can only warn, so they never stop a model.
  • Fail when more than N rows fail: the test fails above this count. Shown for Error tests.
  • Warn when more than N rows fail: the test warns above this count, as long as it doesn't fail.

Under the inputs, a preview shows the result for each count, for example 0–10 rows: pass · 11–100: warn · 101 or more: fail. If the warn threshold isn't below the fail threshold, the preview says the warning can never show.

In dbt terms, a threshold of 0 is stored as !=0, dbt's default, and a threshold of N as >N. For any other condition, such as <5, =0, >=3 or between 1 and 5, click Use a dbt condition and write warn_if and error_if directly. A test stored with another condition opens in that mode.

Only test rows where sets dbt's where config: a SQL condition that limits the rows the test looks at, for example created_at > '2024-01-01'.

Run tests

Choose what to test against at the top of the Tests tab:

  • Live: the published model in your data warehouse.
  • Draft: the SQL that's in the editor now, without publishing it. A model that has never been published can only be tested on its draft.

Click a test's run button, or Run all tests to run every enabled test. Each test shows its result:

ResultMeaning
PassedNo more failing rows than allowed.
WarningAbove the warn threshold, but not above the fail threshold.
FailedAbove the fail threshold.
Could not runThe query failed, for example because a column doesn't exist.
SkippedOn Live, the test's column isn't in the published model yet. Run it on the Draft, or publish first.
500+ failingA run you start returns at most 500 failing rows. When the result depends on whether more rows fail than that, Weld doesn't guess a verdict.

Editing a test clears its last result, since that result was judged under the old settings.

See what failed

Click View failures (or View details) on a test. The panel shows:

  • The failing rows and how many there are.
  • The SQL the test ran, with Open in editor to explore it as a new draft.
  • For a test that couldn't run, the error.

Orchestration runs only keep the number of failing rows, not the rows themselves. When you open a warning or failure from an orchestration run, Weld runs the test again as you and shows the Failing rows now, which can differ from the rows at the time of the run.

Run tests in an orchestration

To run a model's tests on a schedule, add them to an orchestration: on the Tests tab, click Edit schedule and choose the orchestration. The tests then run after the model in every run.

In a run:

  • A test that fails, or could not run, fails the model's job, and the job's error names the test.
  • A test that warns is recorded, and the model's job still succeeds.
  • A test is skipped when its column isn't in the published model, for example a test on a column you've only added in a draft. Skipped tests don't fail the job.
  • Disabled tests don't run.

On the run's page, the Tests status column counts the failed, warned and skipped tests for each model.

Edit, turn off or delete a test

  • Use the switch on a test's row to turn it off. A turned-off test doesn't run in orchestrations, and its row is dimmed. Turn it back on the same way.
  • Open the row's menu and click Edit test to change it, or Delete test to remove it.

Adding, editing and deleting tests is recorded in your workspace's activity.

Tests and AI tools

AI tools connected through the Weld MCP server can list, create, run, update and delete model tests, read a test's failing rows, and find published models that have no tests yet. See the model test tools. Ed can list a model's tests and find models without tests.

Was this page helpful?