Yes, you can write custom tests in Elementary, but there are some important distinctions: -
Custom SQL Tests: Elementary allows you to create custom SQL tests via the UI. These are translated into singular dbt tests in your project. The custom SQL test will pass if the query returns no results and fail if it returns any results. These tests are great for validating complex business logic or relationships that aren't covered by out-of-the-box tests. However, these are not statistical anomaly detection tests—they are assertion-based, like standard dbt tests, and do not automatically apply statistical analysis over a time period. The results of these tests are visible in the Elementary UI, and you can configure alerts, tags, and owners for routing and scheduling purposes. The test is associated with a specific model if you use a dbt ref in your query, and the results will be shown under that model in the UI [Custom SQL Tests](
https://docs.elementary-data.com/features/data-tests/custom-sql-tests) [Custom SQL tests in UI](
https://docs.elementary-data.com/changelog#custom-sql-tests-in-ui) [FAQ](
https://docs.elementary-data.com/oss/general/faq). -
Statistical Anomaly Detection: If you want a test that is statistically calculated over a test period (like Elementary's built-in anomaly detection tests), currently, you cannot define your own custom statistical metric or anomaly monitor type. The available anomaly detection tests (e.g., volume, freshness, column anomalies) are pre-defined, and while you can configure their parameters, you cannot add new statistical monitors or custom metrics for anomaly detection at this time. There are plans to support custom metrics in the future, but this is not available yet [Slack discussion on custom metrics](
https://slack.com/archives/C02CTC89LAX/p1699259667520409).
Summary: - You can write custom SQL tests and have them managed and displayed by Elementary, but these are not statistical anomaly detection tests. - You cannot currently define a custom statistical anomaly detection test or metric that Elementary will calculate over a test period, but this is a planned feature. If you need statistical anomaly detection, you must use the built-in Elementary anomaly tests and configure them as needed. For custom business logic, use custom SQL tests.