
Explanation:
1. Can only be defined on SQL models
The Answer:
contract
2. Errors are returned before the model is built
The Answer:
contract
3. May be configured to customize severity
The Answer:
test
4. May be run on ephemeral models
The Answer:
test
dbt tests and contracts serve different purposes in ensuring data quality and model correctness.
Tests evaluate data after it is produced, while contracts validate the structure of a model before dbt attempts to build it.
A model contract is schema-level enforcement that describes required columns, data types, and constraints.
Contracts can only be applied to SQL models, not Python or ephemeral models. Because contracts validate the model's schema before executing any SQL, dbt surfaces those errors before the model is built, preventing invalid schemas from being deployed.
In contrast, tests evaluate the data after dbt builds a model. Tests can be written generically (unique, not_null, relationships, accepted_values) or as custom SQL tests.
They run after the model is materialized. Tests also allow severity configuration, enabling warnings instead of failures for less critical issues-something contracts do not support.
Tests also run on ephemeral models, because dbt expands ephemeral SQL inline within downstream models, allowing tests to still execute logically against the resulting compiled SQL. Contracts, however, do not apply because ephemeral models never materialize into database objects.
Thus:
* "SQL-only" and "errors before build" # contract
* "custom severity" and "run on ephemeral models" # test
If you want the next question formatted the same way, send it!