> ## Documentation Index
> Fetch the complete documentation index at: https://docs.elementary-data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# freshness_anomalies

> [card] [Generate your anomaly test with Elementary AI](https://elementary-data.com/community)
>
> Let our Slack chatbot create the anomaly test you need.

`elementary.freshness_anomalies`

Monitors the freshness of your table over time, as the expected time between data updates.

Upon running the test, your data is split into time buckets (daily by default, configurable with the `time bucket` field),
and then we compute the maximum time without updates (in seconds) as the freshness value per bucket for the last `training_period` (by default 14 days).

The test then compares the freshness of each bucket within the detection period (last 2 days by default, controlled by the
`detection_period` var), and compares it to the freshness of the previous time buckets.
If there were any anomalies during the detection period, the test will fail.

### Test configuration

*Required configuration: `timestamp_column`*
*Default configuration: `anomaly_direction: spike` to alert only on delays.*

<pre>
  `data_tests:
    -- elementary.freshness_anomalies:
      arguments:
        timestamp_column: column name
        where_expression: sql expression
        anomaly_sensitivity: int
        detection_period:
          period: [hour | day | week | month]
          count: int
        training_period:
          period: [hour | day | week | month]
          count: int
        time_bucket:
          period: [hour | day | week | month]
          count: int
        detection_delay:
          period: [hour | day | week | month]
          count: int
        ignore_small_changes:
          spike_failure_percent_threshold: int
          drop_failure_percent_threshold: int
        anomaly_exclude_metrics: [SQL expression]`
</pre>

```yml Models theme={null}
models:
  - name: < model name >
    data_tests:
      - elementary.freshness_anomalies:
          arguments:
            timestamp_column: < timestamp column > # Mandatory
            where_expression: < sql expression >
            time_bucket: # Daily by default
              period: < time period >
              count: < number of periods >
```

```yml Models example theme={null}
models:
  - name: login_events
    data_tests:
      - elementary.freshness_anomalies:
          arguments:
            timestamp_column: "updated_at"
          config:
            # optional - use tags to run elementary tests on a dedicated run
            tags: ["elementary"]
            # optional - change severity
            severity: warn
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.