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

# Setup

> How to create a Metric Template, assign it to assets with parameter overrides, manage propagation, and run all assignments at once.

<script type="application/ld+json">
  {`{
            "@context": "https://schema.org",
            "@type": "TechArticle",
            "headline": "Metric Template Setup",
            "description": "How to create a Metric Template, assign it to assets with parameter overrides, manage propagation, and run all assignments at once.",
            "url": "https://docs.dqlabs.ai/architecture/metrics/metric-template/setup",
            "publisher": {
              "@type": "Organization",
              "name": "DQLabs Inc",
              "logo": "https://media.brand.dev/332adc35-5bc4-4d2b-bf78-256aa4a5e414.svg"
            }
            }`}
</script>

## Creating a Metric Template

<Steps>
  <Step title="Open the Rule Library">
    Navigate to **Metric** and click the **Metric Template** button at the top of the page. This switches from the metric list to the Rule Library.

    Click **+ Add Metric Template**.

    <Frame>
      <img src="https://mintcdn.com/dqlabs/-PfGmQ9dxOvGkLMa/images/image-121.png?fit=max&auto=format&n=-PfGmQ9dxOvGkLMa&q=85&s=1ad8e8a54d3e725486bb5fef62df3295" alt="Image" width="2598" height="1244" data-path="images/image-121.png" />
    </Frame>
  </Step>

  <Step title="Fill in the template details">
    | Field             | Required | Notes                                                                     |
    | ----------------- | -------- | ------------------------------------------------------------------------- |
    | **Template Name** | Yes      | Use a descriptive name — e.g., `MTART_REGEX_CHECK`, `NULL_RATE_BY_COLUMN` |
    | **Purpose**       | Yes      | Business justification for this rule                                      |
    | **Description**   | No       | What the template checks and when to use it                               |
    | **Dimension**     | No       | e.g., Completeness, Validity — acts as a default for all assignments      |
    | **Threshold**     | No       | Default threshold — can be overridden per assignment                      |

    The **Sub Category** is set to **Parameter** automatically.
  </Step>

  <Step title="Write the SQL with \`{{param\_name}}\` tokens">
    In the SQL editor, write the parameterized query.

    ```sql theme={null}
    SELECT COUNT(*) AS failing_rows
    FROM {{table}}
    WHERE MTART IS NOT NULL
      AND NOT REGEXP_LIKE(MTART, {{mtart_regex}})
    ```

    Prizm auto-detects all `{{param}}` tokens on save and populates the parameter list.

    <Note>
      If the SQL contains `{{column}}` or `{{attribute}}`, the template is flagged **Attribute-only** — it can only be assigned to column-level objects, not table-level assets.
    </Note>
  </Step>

  <Step title="Configure detected parameters">
    For each auto-detected parameter, set:

    | Field         | Options                                                                                                                        |
    | ------------- | ------------------------------------------------------------------------------------------------------------------------------ |
    | **Category**  | `SOURCE` — auto-resolved from asset metadata \| `CONSTANT` — from org-level parameters \| `METADATA` — from the metadata graph |
    | **Type**      | `string`, `date`, `number`, `enum`                                                                                             |
    | **Required**  | Toggle on/off                                                                                                                  |
    | **Default**   | Value used when not overridden per assignment                                                                                  |
    | **Allowlist** | Comma-separated permitted values for ENUM types                                                                                |

    SOURCE parameters (`{{table}}`, `{{schema}}`, `{{attribute}}`, etc.) are configured automatically — no manual setup needed.
  </Step>

  <Step title="Save the template">
    Click **Save Template**. The template is now available in the Rule Library and ready to assign.
  </Step>
</Steps>

***

## Assigning a Template to an Asset

A single template can be assigned to multiple assets. Each assignment creates one executable metric named **`Template Name — Asset Name`**.

<Steps>
  <Step title="Open the assignment form">
    From the Rule Library, find the template and click **Assign**. Alternatively, open an asset's metric tab and select **Add from Template**.
  </Step>

  <Step title="Select the target asset">
    Choose the table, view, or attribute. SOURCE parameters (`{{table}}`, `{{schema}}`, etc.) resolve automatically — no manual entry.
  </Step>

  <Step title="Set parameter overrides">
    The assignment form lists all declared parameters with their template defaults. Override any value specific to this asset:

    |               | Template default          | EMEA override         | APAC override    |
    | ------------- | ------------------------- | --------------------- | ---------------- |
    | `mtart_regex` | *(required — no default)* | `^(FERT\|HALB\|ROH)$` | `^(FERT\|VERP)$` |

    Parameters left blank use the template default. Required parameters with no default must be filled before the assignment can be activated.
  </Step>

  <Step title="Set schedule and threshold">
    Configure the run schedule and optionally override the template's default threshold for this assignment. Overridden values are marked `overridden` vs. `inherited` and are never silently reset when the template default later changes.
  </Step>

  <Step title="Save">
    Click **Save Assignment**. The metric appears in the asset's metric list and runs as a standard metric from that point forward.
  </Step>
</Steps>

***

## Parameter Resolution Order

At run time, values are resolved in this priority:

```text theme={null}
1. SOURCE parameters     — always resolved first from asset metadata (cannot be overridden)
2. Assignment override   — value set per asset at assignment time
3. Template default      — fallback when no override is set
4. Validation error      — if required and no value is found, execution is blocked
```

***

## Updating a Template

Edit the template's SQL or parameters directly in the Rule Library. The following fields propagate to all assignments on their next run:

| Field                   | Propagated |
| ----------------------- | ---------- |
| Query (SQL body)        | ✓          |
| Description             | ✓          |
| Purpose                 | ✓          |
| Rationale               | ✓          |
| Audience                | ✓          |
| Dimension               | ✓          |
| Pass Criteria           | ✓          |
| Threshold Configuration | ✓          |
| Weightage               | ✓          |
| AI Configuration        | ✓          |
| Failed Rows Query       | ✓          |
| Total Records Query     | ✓          |

**Assignment-level overrides are always preserved** — template updates never overwrite them.

| Change              | Effect on assignments                                                      |
| ------------------- | -------------------------------------------------------------------------- |
| SQL body updated    | All assignments use the new SQL on next run                                |
| New parameter added | All assignments gain the param; template default applies unless overridden |
| Parameter renamed   | Assignments with overrides for the old name require manual update          |
| Parameter removed   | Removal blocked if any active assignment has an override for that param    |

<Note>
  Assignments receive an in-app notification when the template changes. Review updated parameters before the next scheduled run.
</Note>

***

## Running Templates

### Run a single assignment

Open the assigned metric on the asset page and click **Run**. If the metric has unresolved runtime parameters, a popup prompts for values before execution.

### Run All — execute every assignment at once

From the Rule Library, open a template and click **Run All**. This executes every metric generated from that template in a single batch.

If any assignment has unresolved runtime parameters, a dialog appears with an **accordion layout** — one section per asset — where you supply values before submitting. All metrics are submitted together and the Timeline updates as each completes.

***

## Viewing Assignments and Timeline

Open a template in the Rule Library and select the **Assignments** tab to see:

* Every asset the template is assigned to, listed as `Template Name — Asset Name`
* The active parameter overrides per assignment
* Run history per assignment: resolved SQL, effective parameters, status, and timestamps

**Multi-asset timeline:** When a template has multiple assignments, the Timeline view shows a **metric dropdown**. Select a specific assignment to view that asset's run history.
