# Use Runtime Variables

Source: https://userguide.qualytics.io/operations/scan/how-tos/use-runtime-variables/

Runtime variables let a quality check reference a value that is supplied when the scan runs, instead of hard-coding it in the check. A common use is a check filter that targets a reporting date or a business unit that changes from one scan to the next.

Related pages: [Scan Settings](https://userguide.qualytics.io/operations/scan/how-tos/scan-settings/) · [Scan API](https://userguide.qualytics.io/operations/scan/api/) · [Scan FAQ](https://userguide.qualytics.io/operations/scan/faq/)

## How Variables Work

Write a variable in a check as a name inside double curly braces, for example `{{ checked_date }}`. When a scan runs, Qualytics replaces each variable with its value and then evaluates the check.

Variables are supported in:

- The check's **Filter Clause**.
- Rule properties that hold an expression, a filter, or a pattern, such as the expression of a Satisfies Expression check or the reference filter of an Aggregation Comparison check.
- Lists of text values, such as the list of an Expected Values check on a text field. Lists of numbers or of true/false values do not accept variables.

In the check editor, fields that accept variables highlight them as you type.

A check filter that uses a variable must still be a valid [Spark SQL WHERE](https://spark.apache.org/docs/latest/sql-ref-syntax-qry-select-where.html) expression once the value is in place. For example:

```sql
transaction_date = {{ checked_date }}
```

> **Info: Scans only**
>
> Variables are filled in during **Scan** operations. Profile and Materialize operations do not use them.

> **Warning: Saving a check does not test the filter with your values**
>
> When you save a check, variables in its filter and reference filter are treated as `null` during validation, so you can save the check before any value exists. This also means a container default or scan value that makes the filter invalid is not caught on save. It only fails when the scan runs. Variables in other rule properties, such as the expression of a Satisfies Expression check, are filled from the container's default values when one exists (the built-in `_qualytics_` variables always have a value) and are otherwise replaced with nothing, so the check can be saved only if the expression is still valid. For example, `o_orderdate <> {{ checked_date }}` cannot be saved unless the container defines a default for `checked_date`. To test a check with real values first, call `POST /api/quality-checks/validate` (or `POST /api/quality-checks/{id}/validate` for an existing check) with the check in `quality_check` and the values in `check_variables`.

## Where Values Come From

A variable can get its value from two places. When the same variable is defined in both, the scan value wins:

| Priority | Source | Use it for |
| --- | --- | --- |
| 1 (lowest) | The container's **Additional Metadata** | Default values that apply to every scan of that container. |
| 2 (highest) | The scan's **Scan Variables**, or `check_variables` in the API | Values for one scan or one schedule. These override the container defaults. |

Qualytics also provides [built-in variables](https://userguide.qualytics.io/operations/scan/how-tos/use-runtime-variables/#built-in-variables). A value you define with the same name as a built-in variable replaces it, so do not start your own variable names with `_qualytics_`.

## Set Default Values on a Container

**Step 1**: Open the container's settings: click the vertical ellipsis next to the container in the datastore's list and select **Settings**. For a Computed Table, Computed File, or Computed Join, you can also use its add or edit form. See [General Settings](https://userguide.qualytics.io/container/settings/general/).

**Step 2**: In **Additional Metadata**, click the plus icon and add one row per variable. The key is the variable name (without the curly braces) and the value is what replaces it.

**Step 3**: Save. Every scan that includes this container now uses these values unless the scan supplies its own.

> **Warning: Scanning several containers at once**
>
> A scan combines the Additional Metadata of every container it includes into a single set of values. If two containers in the same scan define the same key with different values, only one of the values is used. Give each container's variables distinct names, or set the value in **Scan Variables** for that scan.

## Supply Values for a Scan

**Step 1**: Open the Scan operation modal and continue to **Scan Settings**.

**Step 2**: Toggle **Advanced Options** on.

**Step 3**: In **Scan Variables**, add one row per variable you want to set or override for this scan.

**Step 4**: Run the scan, or save it as a schedule. Scheduled scans keep their Scan Variables and use them on every run.

## Supply Values Through the API

Pass the values in the `check_variables` field when calling `/api/operations/run`:

```json
{
    "type": "scan",
    "datastore_id": 42,
    "container_names": ["my_container"],
    "incremental": true,
    "max_records_analyzed_per_partition": null,
    "check_variables": {
        "checked_date": "TIMESTAMP '2026-05-15'"
    },
    "high_count_rollup_threshold": 10
}
```

`"max_records_analyzed_per_partition": null` removes the record limit within the chosen read strategy. This example uses Incremental, so later runs still skip records before the saved baseline. Do not send `0`: it analyzes no records, so the scan finds nothing, and a Full scan with Auto Resolve on can close anomalies that are still open.

Scan schedules accept the same `check_variables` field. For the full payload reference, see [API](https://userguide.qualytics.io/operations/scan/api/).

## Write Values with Explicit Types

A value is inserted into the check exactly as you type it, so it must be valid SQL in that position. Include quotes and casts yourself:

| Variable type | Example value | Resulting filter |
| --- | --- | --- |
| Timestamp | `TIMESTAMP '2026-05-15'` | `transaction_date = TIMESTAMP '2026-05-15'` |
| Date | `DATE '2026-05-15'` | `posting_date >= DATE '2026-05-15'` |
| String | `'EMEA'` | `business_unit = 'EMEA'` |
| Number | `100` | `amount > 100` |

You can also keep the quotes in the check itself, for example `business_unit = '{{ unit }}'`, and supply the value without quotes (`EMEA`).

## Built-in Variables

These variables are always available and do not need a value:

| Variable | Replaced with |
| --- | --- |
| `{{ _qualytics_self }}` | The data being scanned, usable as a table name inside a subquery. |
| `{{ _qualytics_container_id }}` | The identifier of the container the check runs against. |
| `{{ _qualytics_operation_id }}` | The identifier of the scan operation that is running. |

For an example that uses `{{ _qualytics_self }}`, see [Satisfies Expression: How It Works](https://userguide.qualytics.io/data-quality-checks/satisfies-expression/deep-dive/how-it-works/).

*Last updated: October 19, 2026.*
