Custom SQL cloud tests are available on request. Contact the Elementary team to enable them for your account.
How it works
Write a query that returns the rows that violate your expectation. For example:
By default, Elementary stores a limited sample of the returned rows with the test result. You can turn off row samples or change the sample limit.
Disable row samples if the query could return sensitive values that should not be stored with test results.
Cloud test behavior
Like other cloud tests, custom SQL tests:- Are created and configured in the Elementary UI
- Run independently of your dbt pipeline
- Can run on a recurring schedule or on demand
- Appear alongside dbt tests and other monitors in test results, incidents, and coverage views
SQL requirements
A custom SQL test must:- Contain exactly one read-only query
- Use a
SELECTstatement, including queries built with CTEs orUNION - Reference tables by their fully qualified names
- Reference only tables that exist as assets in the Elementary Catalog
Asset linkage and permissions
Elementary derives asset linkage from the tables referenced in the SQL:- If the query references one asset, Elementary links it automatically.
- If it references multiple assets, choose a primary asset during configuration.
Create a custom SQL test
1
Add a custom SQL test
Go to Test Configuration, click Add Test, and choose Custom SQL under Elementary Cloud tests.
2
Write and validate the query
Enter a name, an optional description, and a query that returns failing rows. Validate the query to check its SQL, warehouse compatibility, and referenced assets.
3
Choose the primary asset
If the query references multiple assets, select the asset that the test primarily represents.
4
Configure the result behavior
Set failure and optional warning thresholds. Choose whether to store a sample of failing rows, then configure the row-sample limit and query timeout.
5
Set the schedule and ownership
Choose a schedule, severity, owners, and tags, then submit the test. No pull request is required.
Scheduling
Set the test to run hourly, every few hours, daily, or weekly. You can also run the test immediately with Test now.Edit configuration
Open the test from test results or an incident and go to the Configuration tab. You can update the SQL, thresholds, row-sample settings, timeout, schedule, severity, owners, and tags. When you save an updated query, Elementary validates it again and re-derives its referenced assets. If the query now references multiple assets or no longer references the current primary asset, you must choose a new primary asset. Saving changes re-runs the test with the updated configuration.Test results
Each execution shows its status and the number of failing rows returned. When row samples are enabled, the execution details also show the sampled rows and whether the sample was truncated. Execution errors, such as invalid SQL or a query timeout, are shown separately from failures caused by returned rows.Alerts
Custom SQL test failures map to the Custom SQL tests category in alert rules. Include this category in a rule’s test-type filters to receive alerts. By default, the catch-all alert rule may not include every cloud test category. Review your alert rules if you want custom SQL cloud test failures to notify your team.Comparison with dbt singular tests
dbt singular tests also use SQL queries that return failing rows, but they are managed and executed through your dbt project.
Choose a custom SQL cloud test when you want Elementary to manage the configuration and schedule. Choose a dbt singular test when the validation should live in version-controlled project code and run with your dbt jobs.

