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

# Validator Recipes

> Common validator recipes for Validio, including freshness checks, null validation, volume monitoring, and more.

Validators can be used to validate data for a huge number of use cases. Some recipes for common and useful validations are described below.

> [!TIP]
>
> **Recommendation**
>
> For more customizability we recommend exploring the [Custom SQL recipes](https://docs.validio.io/v11.0/docs/validators/validator-types/custom-sql/custom-sql-validator-recipes.md) and the [SQL filter recipes](https://docs.validio.io/v11.0/docs/filters/filter-types.md#sql-filter-recipes).

***

## Ensure data is up to date, for example data from every supplier

*Validates freshness, for every segment defined by a segmentation field*

| Wizard step | Setting | Value |
| :- | :- | :- |
| Validator type | Validator type | Freshness |
| Source config | Segmentation | `Segmentation field, e.g. supplier_id` |
| Threshold | Threshold type | Dynamic threshold |

Note that [polling interval](https://docs.validio.io/v11.0/docs/sources.md#configuring-a-source) and [window size](https://docs.validio.io/v11.0/docs/windows.md) have a significant impact on freshness validation.

For instance, consider supplier updates occurring around XX:40 every hour, and you have set the window size to hourly. Freshness is assessed against the end of the window, making the expected freshness 20 minutes. If one supplier's data is updated late, say 09:55, the freshness will be reduced to 5 minutes, which is captured by the dynamic thresholds as an anomaly.

Additionally, in this scenario, setting the polling interval to occur every whole hour offers two advantages. First, it enables immediate freshness evaluation right after polling, facilitating prompt notifications. Second, it helps avoid late arrivals. For instance, data with a timestamp of 10:40 arriving at 11:02 will not affect freshness as the poll closes the window at 11:00.

> [!WARNING]
>
> **Caution**
>
> A very frequent polling interval can impact cost and performance, depending on, for example, amount of data and other validators running on the same Source.

***

## Validate a metric per segment, such as revenue per product group

*Validates an aggregated metric, for every segment defined by a segmentation field*

| Wizard step | Setting | Value |
| :- | :- | :- |
| Validator type | Validator | Numeric |
| Config | Metric | Sum |
| Source config | Field | `Field in question, e.g. revenue` |
| Source config | Segmentation | `Segmentation field, e.g. product_group` |
| Threshold | Threshold type | Dynamic threshold |

**Useful variants:**

* Some validations benefit from other metrics than `Sum`, for example `Mean`.
* You can segment on multiple fields, e.g. `product_group` and `country`.

***

## Count NULLs

*Counts records where a field value is NULL*

| Wizard step | Setting | Value |
| :- | :- | :- |
| Validator type | Validator | Volume |
| Config | Metric | Count |
| Source config | Field | No field (use record) |
| Source config | Filter type | Null filter |
| Source config | Filter field | `Field in question` |
| Source config | Operator | is null |
| Threshold | Threshold type | Dynamic threshold |

**Useful variants:**

* Track percentage of NULLs, by setting `Metric` to `Percentage` instead of `Count`.
* You can modify the filter to count something other than NULLs, for example count records where a field value is TRUE, 0 or "".
* Apply a [Segmentation](https://docs.validio.io/v11.0/docs/segmentation.md) to track data per segment, for example, per ad campaign source.
* Use a `Fixed threshold` `Equal` `0` if no NULLs are accepted.

***

## Validate uniqueness, e.g. unique primary keys

*Counts duplicates and ensures that value is always 0*

| Wizard step | Setting | Value |
| :- | :- | :- |
| Validator type | Validator | Volume |
| Config | Metric | Duplicates count |
| Source config | Fields | `Field(s) in question, e.g. customer_id` |
| Threshold | Threshold type | Fixed threshold |
| Threshold | Operator | Equal |
| Threshold | Value | 0 |

**Useful variants:**

* Pick multiple fields is useful, for example, when the primary key is a composition of multiple fields.

***

## Validate a calculated ratio, such as conversion rate

*Calculates and validates a ratio between two fields, for example sales per lead*

| Wizard step | Setting | Value |
| :- | :- | :- |
| Validator type | Validator | Numeric distribution |
| Config | Metric | Sum ratio |
| Source config | Field | `Numerator field, e.g. sales` |
| Reference source config | Sources | `Same as in Source config` |
| Reference source config | Field | `Denominator field, e.g. leads` |
| Reference source config | Window | `Same as in Source config` |
| Reference source config | Window offset | 0 |
| Reference source config | Number of windows | 1 |
| Threshold | Threshold type | Dynamic threshold |

**Useful variants:**

* Some validations benefit from other metrics than `Sum ratio`, for example `Mean ratio`.
* Apply a [Segmentation](https://docs.validio.io/v11.0/docs/segmentation.md) to track data per segment, for example, per customer group.

***

## Validate a time difference, such as mean session duration

*Calculates and validates the difference between to timestamp fields*

| Wizard step | Setting | Value |
| :- | :- | :- |
| Validator type | Validator | Relative time |
| Config | Source field | `Timestamp field, e.g. session_start` |
| Config | Field to subtract | `Timestamp field, e.g. session_end` |
| Config | Metric | Mean difference |
| Threshold | Threshold type | Dynamic threshold |

**Useful variants:**

* Some validations benefit from other metrics than `Mean difference`, for example `Maximum difference`.
* Apply a [Segmentation](https://docs.validio.io/v11.0/docs/segmentation.md) to track data per segment, for example, per customer group.
