<@U088WCP3B4P>, I have table "anomaly_detection_mo...
# ask-elementary-ai
s
@kapa.ai, I have table "anomaly_detection_model" with two fields "object_id" and "object_name". I need to write Anomaly Detection Test to detect if new value in "object_name" is appeared. Can you provide the example of usage.
k
A message from kapa.ai
To detect if a new value appears in the
object_name
field of your
anomaly_detection_model
table, you should use the dimension anomalies test in Elementary. This test monitors the frequency and distribution of values in a specified dimension (column) over time and alerts on unexpected changes, such as the appearance of new values. Here’s how you can configure this in your
schema.yml
(or the relevant dbt model YAML file):
Copy code
yaml models:   - name: anomaly_detection_model     config:       elementary:         timestamp_column: <your_timestamp_column>  # Recommended for time-based monitoring     tests:       - elementary.dimension_anomalies:           dimensions: object_name           # Optionally, you can add a where_expression or adjust time_bucket if needed           # where_expression: <sql_expression>           # time_bucket:           #   period: day           #   count: 1
- Replace
<your_timestamp_column>
with the name of your timestamp column if you have one. This enables time-bucketed anomaly detection. - The
dimensions: object_name
line tells Elementary to monitor the distribution of
object_name
values and alert if new values appear or if the distribution changes unexpectedly. This setup will help you detect when a new
object_name
value appears in your table, as it will be flagged as an anomaly in the dimension distribution monitoring. For best results, use this on low-cardinality fields, but it will work for your use case as described. For more details, see the official documentation on [dimension anomalies](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/dimension-anomalies) and [adding tests examples](https://docs.elementary-data.com/data-tests/add-elementary-tests#adding-tests-examples).