Rules

A rule (an expectation in GX Core terms) is a testable assertion about your data. In Measured, rules are authored directly on a data asset and run together inside a rule group. Measured supports all GX Core built-in expectation types, grouped into categories below, author them by hand or let AI draft them from a profile.

Table-level expectations

These expectations check properties of the entire table.

| Expectation | Description | |---|---| | expect_table_row_count_to_be_between | Row count falls within [min_value, max_value] | | expect_table_row_count_to_equal | Row count equals a specific value | | expect_table_columns_to_match_ordered_list | Column list matches exactly, in order | | expect_table_columns_to_match_set | Column list matches a set (order-independent) | | expect_table_column_count_to_be_between | Number of columns is in range | | expect_table_column_count_to_equal | Number of columns equals a value |

Column existence

| Expectation | Description | |---|---| | expect_column_to_exist | Column is present in the table |

Nullability

| Expectation | Description | |---|---| | expect_column_values_to_not_be_null | No null values in the column | | expect_column_values_to_be_null | All values are null (useful for deprecated columns) |

Type checking

| Expectation | Description | |---|---| | expect_column_values_to_be_of_type | Column has specified type | | expect_column_values_to_be_in_type_list | Column type is one of a list |

Value constraints

| Expectation | Description | |---|---| | expect_column_values_to_be_in_set | Values are members of a set | | expect_column_values_to_not_be_in_set | Values are not members of a set | | expect_column_values_to_be_between | Values fall within [min_value, max_value] | | expect_column_values_to_be_increasing | Values are strictly or non-strictly increasing | | expect_column_values_to_be_decreasing | Values are strictly or non-strictly decreasing |

String matching

| Expectation | Description | |---|---| | expect_column_values_to_match_regex | Values match a regex pattern | | expect_column_values_to_not_match_regex | Values do not match a regex pattern | | expect_column_values_to_match_regex_list | Values match any of a list of regex patterns | | expect_column_values_to_match_like_pattern | Values match a SQL LIKE pattern | | expect_column_values_to_match_strftime_format | Values are valid datetime strings matching a format |

Uniqueness

| Expectation | Description | |---|---| | expect_column_values_to_be_unique | All values in the column are unique | | expect_column_unique_value_count_to_be_between | Cardinality is within a range | | expect_column_proportion_of_unique_values_to_be_between | Proportion of unique values is within a range | | expect_compound_columns_to_be_unique | Combination of columns is unique (composite key) |

Statistics

| Expectation | Description | |---|---| | expect_column_mean_to_be_between | Column mean is within [min_value, max_value] | | expect_column_median_to_be_between | Column median is within range | | expect_column_stdev_to_be_less_than | Standard deviation is below a threshold | | expect_column_sum_to_be_between | Column sum is within range | | expect_column_min_to_be_between | Column minimum is within range | | expect_column_max_to_be_between | Column maximum is within range | | expect_column_quantile_values_to_be_between | Specified quantiles fall within ranges |

Distribution

| Expectation | Description | |---|---| | expect_column_kl_divergence_to_be_less_than | KL divergence from a reference distribution is below a threshold | | expect_column_chisquare_test_p_value_to_be_greater_than | Chi-square p-value is above threshold | | expect_column_bootstrapped_ks_test_p_value_to_be_greater_than | KS test p-value is above threshold |

Cross-column

| Expectation | Description | |---|---| | expect_column_pair_values_a_to_be_greater_than_b | Values in column A are greater than column B | | expect_column_pair_values_to_be_equal | Column A and column B have equal values | | expect_column_pair_values_to_be_in_set | Pairs of values from two columns are in a set | | expect_select_column_values_to_be_unique_within_record | Values across selected columns are unique within each row |

Custom SQL

| Expectation | Description | |---|---| | expect_column_values_to_match_like_pattern_list | Values match any SQL LIKE pattern from a list | | UnexpectedRowsExpectation | A custom SQL query returns zero rows (great for complex rules) |

The mostly parameter

Most row-level expectations accept a mostly parameter (0.0–1.0) that sets the minimum fraction of values that must pass. For example:

{
  "rule_type": "expect_column_values_to_not_be_null",
  "kwargs": {
    "column": "email",
    "mostly": 0.99
  }
}

This passes if at least 99% of rows have a non-null email.

Creating rules in the UI

  1. Open a data assetRules section → Add rule (or Suggest rules for AI drafts)
  2. Select the rule type
  3. Configure parameters and severity (info / warning / error / critical)
  4. Save, then add the asset's rules to a rule group to run them

The AI rule generator suggests appropriate rule types and parameter values from the asset's profile or a plain-English description.

Creating rules via the API

Rules are written to the data asset they belong to:

curl -X PUT https://app.measured.cloud/api/v2/organizations/$ORG/workspaces/$WS/data-assets/{asset_id}/rules \
  -H "Authorization: Bearer $MEASURED_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "data": {
      "rules": [
        { "rule_type": "expect_column_values_to_not_be_null", "kwargs": { "column": "user_id", "severity": "error" } },
        { "rule_type": "expect_table_row_count_to_be_between", "kwargs": { "min_value": 1000, "max_value": 10000000 } }
      ]
    }
  }'

Then reference the asset's rules from a rule group to run them.