All Products
Search
Document Center

DataWorks:Rule templates

Last Updated:Dec 10, 2025

Data Quality provides rule templates to simplify the creation of Specs. The system includes a set of common, built-in templates, and you can also create your own custom templates. Templates contain most of the required Spec settings, so when you create a rule from a template, you only need to configure the remaining settings.

Use system rule templates

The following example shows how to create a rule using the 1, 7, and 30-day average volatility system rule template:

datasets:
  - type: Table
    tables:
      - tb_d_spec_demo
    filter: "dt='$[yyyymmdd]' AND hh='$[hh24-1/24]'"
    dataSource:
      name: odps_first
      envType: Dev
rules:
  - templateId: "SYSTEM:field:avg:flux:1_7_1m_bizdate"
    fields:
      - col_income
    warn: "when > 1%"
    fail: "when > 10%"

The preceding code snippet creates a Data Quality monitoring rule by referencing the 1, 7, and 30-day average volatility system rule template. The parameters are configured as follows:

  • templateId: The rule template ID. For more rule template IDs, see System Rule Template List. You can also create a custom rule template and refer to Use a custom rule template to create a rule.

  • templateParameters: The parameters that the rule template requires. Different templates require different parameters. A common parameter is fields, which specifies the list of fields that the rule monitors.

    For the parameters required by each rule template, see System rule template list.

  • warn/fail: The thresholds.

Use custom rule templates

If system rule templates do not meet your needs, or if you have many custom SQL rules that contain the same SQL statements, you can create custom rule templates.

Define a custom template

The following code snippet shows an example of a Spec configuration for a custom rule template:

name: "Check for number of rows with non-null ID"
id: "1760d075-00bd-43c9-be8f-3c9a4bac35db"
assertion: "id_not_null_row_count = 0"
id_not_null_row_count:
  query: "SELECT COUNT(*) FROM ${table} WHERE dt = '$[yyyymmdd-1]';"
catalog: "ods_layer/real_time_check"

The preceding code snippet defines a simple custom rule template. It includes the following fields:

  • name: The template name.

  • id: The unique identifier for the template. This ID must be globally unique and is used to reference the template.

  • assertion: The logic of the rule. For more information about the syntax, see the assertion field in Data Quality Spec configuration.

    id_not_null_row_count: The metric definition referenced by the assertion in this example. In the query, you can use ${tableName} as a placeholder for the table name. When you create a rule from this rule template, this placeholder is replaced with the name of the table that the rule monitors. You can also directly reference system time parameters. For more information, see Data filtering configuration.

  • catalog: The category of the rule template, which is used for management. Use a forward slash (/) to separate multiple levels of categories.

Threshold settings in custom templates

Fixed and non-fixed thresholds

The following code snippet shows an example of a configuration with a non-fixed threshold:

name: "Check for number of rows with non-null ID"
id: "1760d075-00bd-43c9-be8f-3c9a4bac35db"
assertion: "id_not_null_row_count"
id_not_null_row_count:
  query: "SELECT COUNT(*) FROM ${table} WHERE dt = '$[yyyymmdd-1]';"

Volatility thresholds

name: "Check for number of rows with non-null ID"
id: "1760d075-00bd-43c9-be8f-3c9a4bac35db"
assertion: "change avg last 7 days percent for id_not_null_row_count"
id_not_null_row_count:
  query: "SELECT COUNT(*) FROM ${table} WHERE dt = '$[yyyymmdd-1]';"

Create a rule using a custom template

  • Example 1

    datasets:
      - type: Table
        tables:
          - tb_d_spec_demo
        filter: "dt='$[yyyymmdd]' AND hh='$[hh24-1/24]'"
        dataSource:
          name: odps_first
          envType: Dev
    rules:
      - templateId: "1760d075-00bd-43c9-be8f-3c9a4bac35db"
        # Use fail to define the failure threshold
        fail: "when != 0"
  • Example 2

    datasets:
      - type: Table
        tables:
          - tb_d_spec_demo
        filter: "dt='$[yyyymmdd]' AND hh='$[hh24-1/24]'"
        dataSource:
          name: odps_first
          envType: Dev
    rules:
      - templateId: "1760d075-00bd-43c9-be8f-3c9a4bac35db"
        warn: "when between 1 and 10)"
        fail: "when > 10"
  • Example 2

    datasets:
      - type: Table
        tables:
          - tb_d_spec_demo
        filter: "dt='$[yyyymmdd]' AND hh='$[hh24-1/24]'"
        dataSource:
          name: odps_first
          envType: Dev
    rules:
      - templateId: "1760d075-00bd-43c9-be8f-3c9a4bac35db"
        warn: "when not between -1% and 1%"
        fail: "when not between -10% and 10%"

System rule template list

Id

Template

Required fields

Example

SYSTEM:table:table_count:fixed

Table Row Count, Static Field

pass

templateId: "SYSTEM:table:table_count:fixed"
pass: "when > 0"

SYSTEM:table:table_count:fixed:0

Table Row Count Is Greater Than 0

-

templateId: "SYSTEM:table:table_count:fixed:0"

SYSTEM:table:table_count_delta:fixed:1_bizdate

Table Row Count, 1-day Difference

pass

templateId: "SYSTEM:table:table_count_delta:fixed:1_bizdate"
pass: "when < 10"

SYSTEM:table:table_count_delta:fixed:latest_bizdate

Table Row Count, Previous Epoch Difference

pass

templateId: "SYSTEM:table:table_count_delta:fixed:latest_bizdate"
pass: "when < 10"

SYSTEM:table:table_count:flux:1_7_1m_bizdate

Table Row Count, 1, 7, 30-day Volatility Rate

  • warn

  • fail

templateId: "SYSTEM:table:table_count:flux:1_7_1m_bizdate"
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:table:table_count:flux:1_7_1m_1st_bizdate

Table Row Count, 1, 7, 30-day, And First Day Of The Month Volatility Rate

  • warn

  • fail

templateId: "SYSTEM:table:table_count:flux:1_7_1m_1st_bizdate"
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:table:table_count:flux:1_bizdate

Table Row Count, 1-day Volatility Rate

  • warn

  • fail

templateId: "SYSTEM:table:table_count:flux:1_bizdate"
warn: "when < -1%"
fail: "when < -5%"

SYSTEM:table:table_count:flux:1m_bizdate

Table Row Count, 30-day Volatility Rate

  • warn

  • fail

templateId: "SYSTEM:table:table_count:flux:1m_bizdate"
warn: "when < -1%"
fail: "when < -5%"

SYSTEM:table:table_count:flux:7_bizdate

Table Row Count, 7-day Volatility Rate

  • warn

  • fail

templateId: "SYSTEM:table:table_count:flux:7_bizdate"
warn: "when < -1%"
fail: "when < -5%"

SYSTEM:table:table_count:dynamic_threshold

Table Row Count, Dynamic Threshold

-

templateId: "SYSTEM:table:table_count:dynamic_threshold"

SYSTEM:table:table_count:avg:7_bizdate

Table Row Count, 7-day Average Volatility Rate

  • warn

  • fail

templateId: "SYSTEM:table:table_count:avg:7_bizdate"
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:table:table_count:avg:1m_bizdate

Table Row Count, 30-day Average Volatility Rate

  • warn

  • fail

templateId: "SYSTEM:table:table_count:avg:1m_bizdate"
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:table:table_count:cycle:latest_bizdate

Table Row Count, Previous Epoch Volatility Rate

  • warn

  • fail

templateId: "SYSTEM:table:table_count:cycle:latest_bizdate"
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:table:table_size:fixed

Table Size, Static Field

pass

templateId: "SYSTEM:table:table_size:fixed"
pass: "when > 0"

SYSTEM:table:table_size_delta:fixed:1_bizdate

Table Size, Difference From 1 Day Ago (bytes)

pass

templateId: "SYSTEM:table:table_size_delta:fixed:1_bizdate"
pass: "when > 0"

SYSTEM:table:table_size_delta:fixed:latest_bizdate

Table Size, Previous Epoch Difference

pass

templateId: "SYSTEM:table:table_size_delta:fixed:latest_bizdate"
pass: "when > 0"

SYSTEM:table:table_size:flux:1_bizdate

Table Size, 1-day Volatility Rate

  • warn

  • fail

templateId: "SYSTEM:table:table_size:flux:1_bizdate"
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:table:table_size:flux:1m_bizdate

Table Size, 30-day Volatility Rate

  • warn

  • fail

templateId: "SYSTEM:table:table_size:flux:1m_bizdate"
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:table:table_size:flux:7_bizdate

Table Size, 7-day Volatility Rate

  • warn

  • fail

templateId: "SYSTEM:table:table_size:flux:7_bizdate"
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:table:table_size:dynamic_threshold

Table Size, Dynamic Threshold

-

templateId: "SYSTEM:table:table_size:dynamic_threshold"

SYSTEM:field:null_value:fixed

Number Of Null Values, Static Field

  • fields

  • pass

templateId: "SYSTEM:field:null_value:fixed"
fields:
  - id
pass: "when > 0"

SYSTEM:field:null_value:fixed:0

Number Of Null Records Is 0

fields

templateId: "SYSTEM:field:null_value:fixed:0"
fields:
  - id

SYSTEM:field:null_value_percent:fixed

Number Of Null Values/Total Row Count, Static Field

  • fields

  • pass

templateId: "SYSTEM:field:null_value_percent:fixed"
fields:
  - id
pass: "when > 0"

SYSTEM:field:pattern_match:fixed

Regular Expression Check

  • fields

  • valid

    • regex

  • templateParameters

    • metric

  • pass

templateId: "SYSTEM:field:pattern_match:fixed"
templateParameters:
  metric: invalid_distinct_count
fields:
  - id
valid:
  regex: "[0-9]+"
pass: "when > 0"

SYSTEM:field:pattern_match_date:fixed

Date Format Check

  • fields

  • valid

    • format

  • templateParameters

    • metric

  • pass

templateId: "SYSTEM:field:pattern_match_date:fixed"
templateParameters:
  metric: invalid_count
fields:
  - id
valid:
  format: date_yyyymmdd
pass: "when > 0"

SYSTEM:field:pattern_match_email:fixed

Email Format Check

  • fields

  • templateParameters

    • metric

  • pass

templateId: "SYSTEM:field:pattern_match_email:fixed"
templateParameters:
  metric: invalid_count
fields:
  - id
pass: "when > 0"

SYSTEM:field:pattern_match_idcard:fixed

ID Card Format Check

  • fields

  • templateParameters

    • metric

  • pass

templateId: "SYSTEM:field:pattern_match_idcard:fixed"
templateParameters:
  metric: invalid_count
fields:
  - id
pass: "when > 0"

SYSTEM:field:pattern_match_mobile_number:fixed

Mobile Number Format Check

  • fields

  • templateParameters

    • metric

  • pass

templateId: "SYSTEM:field:pattern_match_mobile_number:fixed"
templateParameters:
  metric: invalid_count
fields:
  - id
pass: "when > 0"

SYSTEM:field:pattern_match_money:fixed

Currency Format Check

  • fields

  • valid

    • format

  • templateParameters

    • metric

  • pass

templateId: "SYSTEM:field:pattern_match_money:fixed"
templateParameters:
  metric: invalid_count
fields:
  - id
valid:
  format: CNY
pass: "when > 0"

SYSTEM:field:pattern_match_number:fixed

Numeric Format Check

  • fields

  • templateParameters

    • metric

  • pass

templateId: "SYSTEM:field:pattern_match_number:fixed"
templateParameters:
  metric: invalid_count
fields:
  - id
pass: "when > 0"

SYSTEM:field:pattern_match_phone_number:fixed

Phone Number Format Check

  • fields

  • templateParameters

    • metric

  • pass

templateId: "SYSTEM:field:pattern_match_phone_number:fixed"
templateParameters:
  metric: invalid_count
fields:
  - id
pass: "when > 0"

SYSTEM:field:duplicated_count:fixed

Number Of Duplicate Values, Static Field

  • fields

  • pass

templateId: "SYSTEM:field:duplicated_count:fixed"
fields:
  - id
pass: "when > 0"

SYSTEM:field:duplicated_count:fixed:0

Field Has 0 Duplicate Values

fields

templateId: "SYSTEM:field:duplicated_count:fixed:0"
fields:
  - id

SYSTEM:fields:duplicated_count:fixed:0

Multiple Fields Have 0 Duplicate Values

fields

templateId: "SYSTEM:fields:duplicated_count:fixed:0"
fields:
  - id
  - name

SYSTEM:field:duplicated_percent:fixed

Number Of Duplicate Values/Total Row Count, Static Field

  • fields

  • pass

templateId: "SYSTEM:field:duplicated_percent:fixed"
fields:
  - id
pass: "when > 0"

SYSTEM:field:count_distinct:fixed

Number Of Unique Values, Static Field

  • fields

  • pass

templateId: "SYSTEM:field:count_distinct:fixed"
fields:
  - id
pass: "when > 0"

SYSTEM:field:count_distinct:flux:1_7_1m_bizdate

Number Of Unique Values, 1, 7, 30-day Volatility Rate

  • fields

  • warn

  • fail

templateId: "SYSTEM:field:count_distinct:flux:1_7_1m_bizdate"
fields:
  - id
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:table:distinct_count:dynamic_threshold

Number Of Unique Values, Dynamic Threshold

  • fields

  • pass

templateId: "SYSTEM:table:distinct_count:dynamic_threshold"
fields:
  - id

SYSTEM:field:count_distinct_percent:fixed

Number Of Unique Values/Total Row Count, Static Field

  • fields

  • pass

templateId: "SYSTEM:field:count_distinct_percent:fixed"
fields:
  - id
pass: "when > 0"

SYSTEM:field:min:flux:1_7_1m_bizdate

Minimum Value, 1, 7, 30-day Volatility Rate

  • fields

  • warn

  • fail

templateId: "SYSTEM:field:min:flux:1_7_1m_bizdate"
fields:
  - id
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:field:min:dynamic_threshold

Minimum Value, Dynamic Threshold

fields

templateId: "SYSTEM:field:min:dynamic_threshold"
fields:
  - id

SYSTEM:field:min:cycle:1_bizdate

Minimum Value, 1-day Volatility Rate

  • fields

  • warn

  • fail

templateId: "SYSTEM:field:min:cycle:1_bizdate"
fields:
  - id
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:field:min:cycle:latest_bizdate

Minimum Value, Previous Epoch Volatility Rate

  • fields

  • warn

  • fail

templateId: "SYSTEM:field:min:cycle:latest_bizdate"
fields:
  - id
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:field:min:flux:1_7_1m_bizdate

Maximum Value, 1, 7, 30-day Volatility Rate

  • fields

  • warn

  • fail

templateId: "SYSTEM:field:min:flux:1_7_1m_bizdate"
fields:
  - id
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:field:max:dynamic_threshold

Maximum Value, Dynamic Threshold

fields

templateId: "SYSTEM:field:max:dynamic_threshold"
fields:
  - id

SYSTEM:field:max:cycle:1_bizdate

Maximum Value, 1-day Volatility Rate

  • fields

  • warn

  • fail

templateId: "SYSTEM:field:max:cycle:1_bizdate"
fields:
  - id
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:field:max:cycle:latest_bizdate

Maximum Value, Previous Epoch Volatility Rate

  • fields

  • warn

  • fail

templateId: "SYSTEM:field:max:cycle:latest_bizdate"
fields:
  - id
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:field:avg:flux:1_7_1m_bizdate

Average Value, 1, 7, 30-day Volatility Rate

  • fields

  • warn

  • fail

templateId: "SYSTEM:field:avg:flux:1_7_1m_bizdate"
fields:
  - id
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:field:avg:dynamic_threshold

Average Value, Dynamic Threshold

fields

templateId: "SYSTEM:field:avg:dynamic_threshold"
fields:
  - id

SYSTEM:field:avg:cycle:1_bizdate

Average Value, 1-day Volatility Rate

  • fields

  • warn

  • fail

templateId: "SYSTEM:field:avg:cycle:1_bizdate"
fields:
  - id
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:field:sum:flux:1_7_1m_bizdate

Sum, 1, 7, 30-day Volatility Rate

  • fields

  • warn

  • fail

templateId: "SYSTEM:field:sum:flux:1_7_1m_bizdate"
fields:
  - id
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:field:sum:dynamic_threshold

Sum, Dynamic Threshold

fields

templateId: "SYSTEM:field:avg:dynamic_threshold"
fields:
  - id

SYSTEM:field:sum:cycle:1_bizdate

Sum, 1-day Volatility Rate

  • fields

  • warn

  • fail

templateId: "SYSTEM:field:sum:cycle:1_bizdate"
fields:
  - id
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:field:sum:cycle:latest_bizdate

Sum, Previous Epoch Volatility Rate

  • fields

  • warn

  • fail

templateId: "SYSTEM:field:sum:cycle:latest_bizdate"
fields:
  - id
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:field:count_distinct_not_in:fixed

Number Of Unique Values Not Matching Enumeration, Static Field

  • fields

  • valid

    • values

  • pass

templateId: "SYSTEM:field:count_distinct_not_in:fixed"
fields:
  - gender
valid:
  values:
    - male
    - female
pass: "when = 0"

SYSTEM:field:count_not_in:fixed

Number Of Rows Not Matching Enumeration, Static Field

  • fields

  • valid

    • values

  • pass

templateId: "SYSTEM:field:count_not_in:fixed"
fields:
  - gender
valid:
  values:
    - male
    - female
pass: "when = 0"

SYSTEM:field:count_not_in:fixed:0

Number Of Rows Not Matching Enumeration Is 0

  • fields

  • valid

    • values

templateId: "SYSTEM:field:count_not_in:fixed"
fields:
  - gender
valid:
  values:
    - male
    - female

SYSTEM:field:field_enum:fixed

Enumeration Value, Custom, Static Field

  • fields

  • valid

    • values

  • templateParameters

    • metirc

  • pass

templateId: "SYSTEM:field:count_not_in:fixed"
templateParameters:
  metric: invalid_count
fields:
  - gender
valid:
  values:
    - male
    - female
pass: "when > 0"

SYSTEM:field:all_discrete_count:fixed

Discrete Value (status Value), Static Field

  • fields

  • pass

templateId: "SYSTEM:field:all_discrete_count:fixed"
fields:
  - gender
pass: "when > 0"

SYSTEM:field:discrete_group_count:fixed

Discrete Value (number Of Groups), Static Field

  • fields

  • pass

templateId: "SYSTEM:field:discrete_group_count:fixed"
fields:
  - gender
pass: "when > 0"

SYSTEM:field:discrete_group_count:dynamic_threshold

Discrete Value (number Of Groups), Dynamic Threshold

fields

templateId: "SYSTEM:field:discrete_group_count:dynamic_threshold"
fields:
  - gender

SYSTEM:field:discrete_value_count:dynamic_threshold

Discrete Value (status Value), Dynamic Threshold

fields

templateId: "SYSTEM:field:discrete_value_count:dynamic_threshold"
fields:
  - gender

SYSTEM:field:discrete_group_count:cycle:latest_bizdate

Discrete Value (number Of Groups), 1-day Volatility Rate

  • fields

  • warn

  • fail

templateId: "SYSTEM:field:discrete_group_count:cycle:latest_bizdate"
fields:
  - gender
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

SYSTEM:field:all_discrete_metrics:fluxdiscrete:1_7_1m_bizdate

Discrete Value (number Of Groups And Status Values), 1, 7, 30-day Volatility Rate

  • fields

  • warn

  • fail

templateId: "SYSTEM:field:all_discrete_metrics:fluxdiscrete:1_7_1m_bizdate"
fields:
  - gender
warn: "when not between -5% and 5%"
fail: "when not between -10% and 10%"

Appendix: Configuration instructions for custom range system templates

The following custom range system templates are configured differently from standard system templates and require separate configuration.

  • Conditional Match Percentage, Custom Range

    rules:
      - assertion: "matched_row_percent = 0"
        filter: "id IS NULL"
  • Field Minimum Value, Custom Range

    rules:
      - assertion: "anomal detection for min(income)"
  • Field Maximum Value, Custom Range

    rules:
      - assertion: "change avg last 7 days percent for max(income)"
        warn: "when > 0.1%"
        fail: "when > 0.5%"
  • Field Average Value, Custom Range

    rules:
      - assertion: "change var last 30 days percent for avg(income)"
        warn: "when < -0.1%"
        fail: "when < -0.5%"
  • Field Sum, Custom Range

    rules:
      - assertion: "change 1 days ago percent for sum(income)"
        warn: "when not between -0.1% and 0.1%"
        fail: "when not between -0.5% and 0.5%"
  • Custom SQL

    assertion parameter, see Define custom metric rules.
    rules:
      - assertion: "change percent for id_not_null_count"
        id_not_null_count:
          query: "SELECT COUNT(*) AS cnt FROM tb_spec_demo WHERE dt = '$[yyyymmdd]'"
        warn: "when not between -0.1% and 0.1%"
        fail: "when not between -0.5% and 0.5%"