Contract Language reference
A Soda data contract is a YAML document that contains data quality checks. The checks in a Soda data contract are similar to unit tests for testing software. Verifying a contract means evaluating the checks against the actual data. If contract verification fails, notifications can be sent out or the new data can be stopped from being released to users.
This page documents the necessary contract structure and the supported check types, filters, and configuration options available in soda's data contract language.
Contract YAML document structure
Example
A Soda data contract YAML must include the following blocks:
A top-level
dataset:keyOne of the following:
A
checks:block, if you’re defining dataset-wide checksA
columns:list
dataset: datasource/db/schema/dataset #mandatory dataset fully qualified name
checks: #dataset level checks
- schema:
- row_count:
columns: #columns list
- name: id
checks: # column level checks (optional)
- missing:
- name: name
checks:
- missing:
threshold:
metric: percent
must_be_less_than: 10
- name: size
checks:
- invalid:
valid_values: ['S', 'M', 'L'] A key can appear only once in each mapping. A repeated key is a YAML syntax error. The message names the key, as in YAML syntax error: found duplicate key "checks", and gives the file, line and column of its second occurrence.
Dataset fully qualified name
Every contract must have a dataset fully qualified name that follows the structure below:
Casing has to match the casing in the data source.
A dataset fully qualified name is composed of 3 parts, all slash-separated:
The data source name: This is the name of the data source in which the dataset exists. The data source name is configured in a data source YAML configuration file or in Soda Cloud.
A list of prefixes: Prefixes represent the full list of hierarchical elements of the data source, like the database name and the schema name. Postgres, for example, has a database name and a schema name as prefixes. Databricks has catalog and schema as prefixes. MySQL has a single prefix, the database, because it has no schema level below the database. Prefix names are also slash-separated.
The dataset name: The name of the table or view.
Columns
Every contract must include a list of columns. If a schema check is configured, this list can be used to validate the presence, data type, and order of columns.
Each column entry includes:
name: the column name (required)data_type(optional): used by the schema checkcharacter_maximum_length(optional): used by the schema check to verify the maximum character length of a string column (e.g.VARCHAR(100))numeric_precision(optional): used by the schema check to verify the precision (total number of digits) of a numeric column (e.g.NUMERIC(10,2)has precision 10)numeric_scale(optional): used by the schema check to verify the scale (digits after the decimal point) of a numeric column (e.g.NUMERIC(10,2)has scale 2)datetime_precision(optional): used by the schema check to verify the fractional seconds precision of a datetime column (e.g.TIMESTAMP(6)has precision 6)checks(optional): a list of checks that apply only to that columntypeThreshold keys (for any check that needs a threshold, such as
must_be,must_be_between, etc.)
Example:
Checks
The checks section defines the quality rules and expectations for your dataset. Checks can be written at two levels:
Dataset-level: Rules that apply to the dataset as a whole (e.g., row count, schema, freshness, duplicates across multiple columns).
Column-level: Rules that apply to a specific column (e.g., missing, invalid, duplicate on a single column).
Each check entry includes:
typecolumn:(not required to compile)Threshold keys (for any check that needs a threshold, such as
must_be,must_be_between, etc.)
Example of a dataset-level checks block:
Example of column-level checks block:
Each check defines what “good data” looks like, ensuring that your dataset meets the expected standards.
You can customize each check by adding filters, thresholds, or variable references depending on your specific use case. Learn more about the different check types on this page.
Schema check
A Schema check verifies that the structure of a dataset matches the expectations defined in the contract—such as required columns, data types, and optional constraints. It ensures that changes to the dataset schema (like missing columns, unexpected data types, or reordered fields) are detected early, helping maintain stability and trust in your data.
Example:
Example with data type parameters:
You can further constrain a column's type by declaring character_maximum_length, numeric_precision, numeric_scale, or datetime_precision. The schema check fails if the data source reports a different value.
Column keys used by the schema check:
The schema check uses the columns as specified in the contract and compares them with the measured dataset columns as as the expected columns.
name
The name of the column. The name is case sensitive.
No
data_type
The data type of the column as is returned by the metadata from the data source. Data types are compared case insensitive.
Yes
character_maximum_length
The character maximum length. This represents the maximum length for data types like VARCHAR(255).
Yes
numeric_precision
The numeric precision (total number of digits). For example, NUMERIC(10,2) has precision 10.
Yes
numeric_scale
The numeric scale (number of digits after the decimal point). For example, NUMERIC(10,2) has scale 2.
Yes
datetime_precision
The fractional seconds precision for a datetime column. For example, TIMESTAMP(6) has precision 6.
Yes
Check configuration keys:
allow_extra_columns
Specifies if columns other than the ones listed in the contract are allowed in the dataset. Values are true or false. Default is false, which means that all columns in the dataset must be specified in the contract.
Yes
allow_other_column_order
Specifies if column ordering must be exact the same as in the contract YAML document. Values are true or false. Default is false, which means that columns must appear in the order as in the contract.
Yes
Row count check
A Row Count check verifies that the dataset contains the expected number of rows. It ensures that the data source has at least a minimum number of records and no unexpected gaps. This is a fundamental check to confirm the presence and completeness of data in a dataset.
Example:
Check configuration keys
Freshness check
A freshness check verifies if data is not too old by measuring the period between the current time and the most recent timestamp present in a given column.
Example:
To warn before the data goes stale, add a second threshold under additional. See Warn and fail thresholds.
Check configuration keys
column
Specifies a timestamp column that represents the time of the row or
No
threshold
It defines the acceptable data age limit. It sets the maximum time allowed between the current time and the newest timestamp found in the target column.
unit: The time unit used for the threshold, e.g.,minute,hour,day.
No
Missing check
A Missing check verifies that a specific column does not contain null or empty values beyond an acceptable threshold. It ensures that critical fields are populated and helps catch incomplete or corrupted data that could impact downstream processes.
Example:
Check configuration keys
missing_values
The list of values is considered missing. NULL is always considered a missing value and doesn't need to be included
No*
missing_format
A SQL regex that matches with missing values. (Advanced)
No*
threshold
The default missing check threshold verifies there are no missing values in the column. Thresholds
Yes
* there are several configuration keys to configure the missing values. At least one missing configuration is required.
Configure extra missing values in a list
Configure a list of values that, apart from NULL, must also be considered as missing values. Typical examples are '-', 'No value', 'N/A', 'None', 'null', -1, 999
Configure extra missing values with a regular expression
Configure a SQL regular expression that, apart from NULL, also matches values that are considered as missing values. Only supported for columns having a text data type
The regex syntax must match the SQL engine of the data source.
The name is a human-readable description of what the regex does. It helps explain the purpose of the pattern, making it easier for others to understand the intent of the check.
Invalid check
An Invalid check verifies that the values in a column conform to a set of allowed formats, values, or constraints. It helps catch data that does not meet the expected standards, such as incorrect formats, out-of-range values, or entries that violate business rules.
Example with valid values:
Check configuration keys
valid_values
A list of valid values
No*
valid_format
A SQL regular expression that matches with valid values
No*
valid_reference_data
References a dataset and column that contains valid values
No*
valid_min
Valid values must be greater or equal than the configured value
No*
valid_max
Valid values must be less or equal than the configured value
No*
valid_length
The fixed length of valid values
No*
valid_min_length
The minimum length of valid values
No*
valid_max_length
The maximum length of valid values
No*
invalid_values
A list of invalid values
No*
invalid_format
A SQL regular expression that matches with invalid values
No*
threshold
The default invalid check threshold ensures there must not be any invalid values. Thresholds
Yes
* there are several configuration keys to configure the invalid values. At least one validity configuration is required. Multiple validity configurations can be combined.
Example with a regular expression
Format is only supported for string data type.
The regex syntax must match the SQL engine of the data source.
The name is a human-readable description of what the regex does. It helps explain the purpose of the pattern, making it easier for others to understand the intent of the check.
Example minimum and maximum values:
valid_min and valid_max can be used independently.
It's supported on columns with numerical data types.
Example minimum and maximum length:
valid_length , valid_min_length and valid_max_length can be used independently.
Example with a reference dataset
valid_reference_data has 2 nested configurations:
dataset: fully qualified dataset name. Limitation: The reference dataset must be in the same data source.column: the name of the column containing the valid values
Commonly referred to as a reference check or referential integrity check.
Duplicate check
A Duplicate check ensures that values in a column or combination of columns are unique, helping prevent data integrity issues. It can be used at the column level or dataset level.
Single column duplicate check
Configuration keys:
filter
Check filter
Yes
Multi-column duplicate check
Configuration keys:
columns
List of column names
No
threshold
The default duplicate check threshold requires that all values are unique. Data Contract Language Reference ✅
Yes
Aggregate check
An Aggregate check verifies that the result of an aggregate function, such as avg, sum, min, max, or count—meets the expected thresholds. It helps ensure that summary statistics over a column remain within acceptable ranges and that key metrics derived from your data stay accurate and consistent.
Example:
Check configuration keys
function
Supported by all data sources: avg, avg_length, max, min, max_length, min_length, sum
No
Metric check
A Metric check validates the result of a custom SQL expression or query against a threshold. It supports complex business logic, calculated metrics, or cross-column relationships. Metric checks can be defined at the dataset level (across multiple columns) or column level (single column).
For better performance, we recommend SQL expressions over full SQL queries—they’re simpler to write and can be combined with other checks in a single query.
Verify a SQL expression value against a threshold
Example at the dataset level:
Example at the column level:
Check configuration keys
expression
A SQL expression that produces the numeric metric value that will be compared with the threshold.
No
Verify a SQL query value against a threshold
Example at the dataset level:
Example at the column level:
query
A SQL query that produces a single numeric metric value that will be compared with the threshold.
No
Failed rows check
A Failed Rows check identifies rows that violate a specific condition, such as a filter or SQL expression. It helps pinpoint problematic data like outliers or rule violations and can save references for further review.
Failed Rows checks can apply at the dataset level (testing conditions across multiple columns) or at the column level (validating individual column values).
We recommend using SQL expressions over full SQL queries for simplicity and efficiency—they allow combining multiple checks into a single query for better performance.
Verify failed rows with a SQL expression
Example at the dataset level:
Example at the column level:
Check configuration keys
Expression
A SQL expression, used as the WHERE clause, that produces any tabular data indicating failures with the data. An expression returning zero rows indicates there is no problem with the data.
No
Verify and visualize failed rows with a SQL query
Example at the dataset level:
Example at the column level:
Check configuration keys
query
A SQL query that produces any tabular data indicating failures with the data. An expression returning zero rows indicates there is no problem with the data.
No
rows_tested_query
A SQL query that returns a single numeric value representing the total number of rows tested by the check. When provided, Soda stores the result as check_rows_tested on the check result.
Yes
threshold
The default is that there should be no failed rows. The threshold can only be count-based for non-licensed organizations. Thresholds
Yes
Report the percentage of failing rows
Soda can also report the percentage of failing rows on a failed_rows check by computing total rows tested at scan time, so you can express thresholds like "fewer than 1% of rows may fail" instead of absolute counts. This requires a Teams or Enterprise license, and running checks via Soda Runner.
Configure rows_tested_query alongside query in a Data Contract to calculate the total number of rows that were tested.

This allows you to see percentage of failing rows in a given check:

The rows_tested_query must return a single numeric value representing the total number of tested rows.
Example at the dataset level:
Reconciliation checks
Reconciliation checks validate that a target dataset matches one or more source datasets, ensuring that data remains consistent after migrations, in pipelines, or during synchronizations. They can be used for both metric-level (aggregate) validation and row-level (record-by-record) validation.
Documentation for reconciliation checks is available in Reconciliation checks
Group By check
A group by check allows you to run validations on aggregated metrics per group of records based on one or more fields. You can then apply thresholds to metrics like counts, sums, or averages for each group.
Follow the private PyPi installation flow to set up your environment and install the necessary Soda extensions.
Verify a SQL query value against a threshold
Example at the dataset level:
Check configuration keys
query
SQL query returning grouping fields and metrics
No
fields
List of column(s) used to group results
No
metric_name
Metric (from query alias) used for threshold evaluation
group_tested_rows
Query alias containing the number of rows tested per group
Yes
Percentage thresholds for Group By checks
To use a percentage threshold on a group_by check, the query must return both:
the metric value to evaluate, referenced by
metric_namethe number of rows tested for each group, referenced by
group_tested_rows
Soda evaluates the percentage threshold independently for each group.
group_tested_rows is required when using threshold.metric: percent.
Common check configurations
Check filter
Most checks support a filter to limit the rows on which the check applies:
Note: If a dataset filter is configured, both the dataset and the check filter will be applied.
For a check in a contract scope, the check filter narrows the scope's filter instead of the dataset filter.
Column expression
All column-level checks (except failed_rows check type) as well as the dataset-level Freshness check, support a column_expression configuration that allows you to modify the column value before the check is evaluated. You can optionally define:
This SQL expression:
Uses the SQL dialect of your connected data source.
Is applied during query generation.
Modifies the column value before the check is evaluated
Soda then runs the check against the result of that expression instead of the raw column.
You can use column_expression to:
Access and validate nested properties in structured columns (for example, JSON, STRUCT, or OBJECT fields).
Cast data types before applying checks (e.g., convert a string to a date for freshness validation).
Reuse standard Soda checks (freshness, missing, validity, etc.) without writing custom SQL.
Define a column expression at the column level
You can define column_expression at the column level so that it applies to all checks on that column.
Override at check level
You can also define a column_expression inside an individual check:
If both column-level and check-level column_expression are defined, the check-level expression overrides the column-level expression.
Use Cases
Thresholds
Every check (except the schema check) has a metric value that is evaluated and produces a check outcome. The threshold is the check part that specifies which numeric values make the check pass or fail.
An example threshold is: "The missing count metric value must be less than 5."
A threshold always compares the check's own metric, never the values in the column. On a missing check that metric is the number of missing values, on a duplicate check the number of duplicates, on an aggregate check the result of the function. So the example above passes when the column has fewer than 5 missing values, whatever those values are.
To constrain the values in a column, use an invalid check with valid_min / valid_max or valid_values.
Use one of the following threshold configuration keys to specify an open range.
must_be
The metric value must be equal to the configured value
must_not_be
The metric value must be different from the configured value
must_be_greater_than
The metric value must be greater than the configured value
must_be_greater_than_or_equal
The metric value must be greater than or equal to the configured value
must_be_less_than
The metric value must be less than the configured value
must_be_less_than_or_equal
The metric value must be less than or equal to the configured value
must_be_between
The metric value must be between the acceptable bounds for a metric. Configure exactly one greater_than or greater_than_or_equal bound and exactly one less_than or less_than_or_equal bound; a strict bound can be combined with an inclusive one. The bounds are specified as nested properties under must_be_between.
must_be_not_between
The metric value must not be between the acceptable bounds for a metric. Configure exactly one greater_than or greater_than_or_equal bound and exactly one less_than or less_than_or_equal bound; a strict bound can be combined with an inclusive one. The bounds are specified as nested properties under must_be_not_between.
A threshold takes at most one of these keys. To compare the same metric against a second boundary at a different severity, add an additional threshold. See Warn and fail thresholds.
Use a closed range to ensure metric values are between 2 boundaries.
Example:
Use
greater_thanorgreater_than_or_equalto specify the lower boundUse
less_thanorless_than_or_equalto specify the upper bound
Use an open range to ensure metric values are outside 2 boundaries.
Example:
Use
less_thanorless_than_or_equalto specify the lower boundUse
greater_thanorgreater_than_or_equalto specify the upper bound
Set a threshold as a percentage
To specify a threshold as a percentage of the total, add metric: percent to the threshold.
The metric property has 2 possible values: count, the default, and percent.
Percentage-based thresholds are only available on checks where the metric value can be expressed as a percentage of a total value. These are:
Missing checks
Invalid checks
Duplicate checks
Failed rows query checks (only when
rows_tested_queryis configured on the check)
Note that the total value refers to the total number of rows checked. In the case of a dataset filter or a check filter, the total refers to the number of rows passing the filters.
Example:
Warn and fail thresholds
A check can carry a second threshold on the same metric, so that a value raises a warning before it breaches the contract. Add the second threshold under additional, and give the two thresholds different level values.
The level property has 2 possible values: fail, the default, and warn. A threshold without a level is a fail threshold, so it is enough to mark the other one level: warn. Keep metric (or unit, for a freshness check) on the outer threshold, where it applies to both.
Example:
The check still produces a single result: fail when the fail threshold is breached, warn when only the warn threshold is breached, and pass otherwise. A value that breaches both reports fail.
Which threshold goes on the outside does not matter, only that the two levels differ. The check above can equally be written with the warn threshold on the outside:
Prefer the fail threshold on the outside while older runners are still in use: a runner that predates additional verifies the outer threshold alone, and with this spelling that leaves a warn-only check (see the version note below).
Warn instead of fail
To raise a warning without adding a fail obligation to the contract, add level: warn to a threshold that has no additional threshold. The check then reports warn instead of fail when the threshold is breached.
Example:
Set warn and fail thresholds on a freshness check
A freshness check keeps unit on the outer threshold, where it applies to both thresholds.
Example:
Combine ranges into warn and fail zones
Either threshold can hold a must_be_between or must_be_not_between range, so one check can define four boundaries: an outer pair the metric must stay within, and an inner pair it should stay within. A value between the two pairs produces a warning; a value outside the outer pair fails.
Example:
With this threshold, an average of 75 passes, 45 warns, and 120 fails.
Rules for an additional threshold
A threshold takes at most one
additionalthreshold, and the outer threshold must carry a comparison of its own.Each of the two thresholds holds exactly one comparison: one
must_be_*key, or onemust_be_betweenormust_be_not_betweenrange.An
additionalthreshold takes only that comparison and an optionallevel.metric,unit, and a nestedadditionalare not allowed inside it.The two levels must differ. Because a threshold without a
levelis a fail threshold, a check has at most one fail threshold and at most one warn threshold.Make the warn threshold tighter than the fail threshold. A warn threshold that is looser than, or equal to, the fail threshold never produces a warn result on its own, and Soda logs a warning when it detects this.
Check names
The name property provides a human-readable description for a check. It helps explain the purpose of the check in plain language, making it easier for users to understand the intent behind each rule, especially when reviewing results in Soda Cloud.
For example, instead of relying on technical details like a regex pattern or threshold, a well-written name offers a simple summary, such as:
In this example, the name ("Email format") clarifies the purpose of the regex. This is particularly helpful for non-technical users reviewing the contract or verification results.
Best Practices for Check Names:
Write check names in plain language.
Focus on the intent or business rule the check enforces.
Avoid repeating technical details already visible in the check configuration.
The name Property is optional but highly recommended for improving clarity and collaboration.
By default, the check name is the check type.
Check Attributes
Use attributes to label, sort, and route your checks in Soda Cloud. Attributes help you organize checks by properties such as domain, priority, location, and sensitivity (e.g., PII).
Learn how to leverage attributes with Notifications and Browse datasets.
Apply Attributes to Checks
You can add attributes directly to individual checks. For example:
Attributes can also hold list values:
Set Default Attributes at the Top Level
You can also define default attributes at the dataset level. These attributes apply to all checks, unless overridden at the individual check level.
The top-level check_attributes do not reach the checks of a contract scope. Those checks get the scope's own check_attributes, with the check's attributes on top.
Filter checks by attributes at runtime
Attributes can also be used to select which checks to run during contract verification using the --check-filter CLI option. For example, -cf attributes.severity=critical runs only checks with severity: critical.
For list-valued attributes (e.g., tags: [prod, critical]), use -cf attributes.tags=prod to match any check where the list contains prod, or -cf "attributes.tags=[prod,critical]" to match the exact list.
Learn more in the CLI reference.
Attribute Validation in Soda Cloud
When publishing contract results to Soda Cloud, all check attributes must be pre-defined in Soda Cloud. If any attribute used in a contract is not registered in your Soda Cloud environment, the results will not be published, and the data contract scan will be marked as failed.
Learn how to configure attributes in Soda Cloud: Check and dataset attributes.
Check qualifiers
When sending results to Soda Cloud, check qualifiers ensure that the checks in the source YAML document can be correlated with the checks in Soda Cloud.
By default, every check in a contract has a qualifier. Contracts generated through Soda Cloud (via the contract editor, Contract Copilot, Contract Autopilot, or the skeleton generator) populate a qualifier on every check, including the first check of each type. The example below shows the form you'll see in generated contracts:
However, in hand-written contracts, the qualifier is only strictly required when a checks section contains multiple checks of the same type: Soda needs distinct qualifiers to give each check a unique identity. The first check of a given type can omit the qualifier; the absence of one is treated as a distinct identity from any qualifier value. Both of the following are valid:
Any text or numeric value is allowed as the qualifier.
Check remediation
The remediation property tells Soda Cleanse how to fix the rows that fail a check. Cleanse reads it from the contract in Soda Cloud and uses it to suggest a fix for each failed row.
description
A short note about the remediation, shown in Soda Cleanse.
Yes
strategy.type
One of llm, sql, constant, or manual.
No
strategy.prompt
llm only. The instruction for the LLM. Cleanse sends it with the full failed row.
No
strategy.tools
llm only. A list of tools the LLM can call, each with a name (web_search or google_address_validation) and an optional description.
Yes
strategy.references
llm only. A list of reference datasets the LLM can look up values in, each with a type (table or column), a name, and an optional description.
Yes
strategy.query
sql only. The SQL query that returns the fixed value. {value}, {column}, and {<column_name>} are replaced with the failed value, the column name, and that column's value in the failed row, as plain text without escaping.
No
strategy.value
constant only. The value to use for every failed row. Use null to clear the field.
No
strategy.instruction
manual only. Guidance for the reviewer who enters the value.
Yes
strategy.fallback.instruction
llm and sql only. Guidance shown to the reviewer when the fix falls back to manual.
Yes
strategy.fallback.confidence_threshold
llm and sql only. A value from 0 to 1. Below this confidence, the fix falls back to manual. Defaults to 0.5.
Yes
The remediation property is supported on missing, invalid, and failed_rows checks at the column level with all four strategies, and on duplicate checks and dataset-level failed_rows checks with the llm and manual strategies.
Configure a filter for all checks
A dataset filter ensures that all checks in the contract are only applied to a subset of the rows in the dataset.
This is most commonly used to apply all checks to the latest time partition of the data. Each time new data is appended to an incremental dataset, the contract verification should evaluate the checks only on the rows in the latest time partition.
The dataset filter does not apply to the checks of a contract scope. The scope's own filter replaces it, and the checks of a scope without a filter read every row of the dataset.
Make contracts dynamic with variables
Variables allow dynamic substitution of values in contracts. They help you:
Parameterize values that differ across environments, datasets, or schedules.
Reuse values in multiple places within the same contract to reduce duplication and improve maintainability.
Variables can be used in filters, checks, thresholds, and more.
Declare variables at the top of the contract:
The default value is optional. Variables without a default are required when verifying a contract (see below). If you don't specify a default value, don't forget the colon (:) after the variable name.
Use variables in other places in the contract with syntax: ${var.VARIABLE_NAME}
You can specify variables values when verifying a contract:
Allowed variable type
Soda currently supports only string and numeric variables, meaning that variables must be represented as either text values or numbers. Other variable types (such as boolean, date/time, arrays, or complex objects) are not supported at this time, so any inputs should be formatted or converted into one of these two supported formats before being used in Soda.
Soda variables
${soda.NOW} is a built-in variable that provides the current timestamp at the moment of scan execution, allowing you to create dynamic filters relative to the time of scan execution. For example, to check for records in the last 24 hours.
Schedule a contract verification
Soda Cloud can execute the contract verification on a time schedule.
First, configure the time schedule in the contract.
This defines a cron-based schedule to trigger contract verification
Requires the data source to be configured in Soda Cloud with Soda Runner
Second, publish the contract to Soda Cloud.
Contract scopes
A contract scope is a named slice of the dataset with its own filter. Declare scopes under the top-level scopes key, then put a check in a scope with scope: <key> in the check body. Checks without a scope are the base checks, and they run as in a contract without scopes.
Use scopes to test several slices of one dataset from one contract, such as one scope per region, each with its own filter, check attributes and schedule. The same check can appear in more than one scope. Data Standards do not support contract scopes.
Follow the private PyPi installation flow to set up your environment and install the necessary Soda extensions.
In this contract:
The first
missingcheck and the firstrow_countcheck are base checks. They read the orders of the last day, through the top-levelfilter, and carry the attributedomain: Sales.The checks with
scope: euread the EU orders of the lastLOOKBACK_DAYSdays. The top-levelfilterdoes not reach them, so theeufilter repeats a date condition of its own. Their attributes come from the scope'scheck_attributes.The
invalidcheck onamountnarrows theeuscope further with its ownfilter.all_ordershas nofilter, so itsduplicatecheck reads every row of the dataset. It declares nocheck_attributes, so that check has no attributes at all.
Scope configuration keys
name
Display name of the scope.
No
description
Description of the scope.
Yes
filter
SQL filter for the checks of the scope, without the WHERE keyword. It replaces the top-level filter for these checks. It can use variables, like the top-level filter.
Yes
check_attributes
Default attributes for the checks of the scope. A check's own attributes override them. The top-level check_attributes do not apply to the checks of a scope.
Yes
schedule
Schedule of the scope. See the schedule keys below.
Yes
Schedule configuration keys
cron
Cron expression in the format minute hour day month weekday, such as "0 6 * * *".
No
timezone
Time zone for the scheduled runs of the scope.
Yes
variables
Variable values for the scheduled runs of the scope. Each value is a string or a number.
Yes
A scope and its schedule take no other keys. When you publish the contract, Soda Cloud gives each scope that has a schedule a scheduled scan of its own, which runs only the checks of that scope. soda contract verify does not run on a schedule, so it does not act on this key.
Scope key rules
A scope key starts with a lowercase letter, followed by at most 63 lowercase letters, digits, _ or -. It matches the pattern ^[a-z][a-z0-9_-]{0,63}$.
These keys are reserved:
base, which names the checks without a scope.true,false,null,yes,no,on,off,yandn, which YAML parsers can read as a boolean or null.
A check takes one scope, and its value is the key of a scope the contract declares. scope: base and an empty scope: are errors. To make a check a base check, leave scope out.
A scope key is fixed, so neither a scope key nor a check's scope can use a variable. A check that took its scope from a variable would move to another scope from one run to the next, with a new identity and history each time. Variables still work in a scope's filter, name, description and schedule.
Each of the following is a parse error that names the key and its location in the file:
An invalid or reserved scope key.
A key a scope or its schedule does not take.
A scope without a
name, or a schedule without acron.A check
scopethat names no declared scope, such asCheck references unknown scope 'apac'. Declared scopes: ['eu', 'all_orders'].scope: baseorscope: nullon a check.A variable in a scope key or in a check's
scope, such asscope: ${var.REGION}.
soda contract test, soda contract verify and soda contract publish exit with code 3 on these errors.
Filters and attributes of scoped checks
Top-level filter
Applies
Does not apply. The scope's filter replaces it.
Scope filter
Does not apply
Applies. A scope without a filter reads every row of the dataset.
Check filter
Narrows the top-level filter
Narrows the scope's filter
Top-level check_attributes
Apply
Do not apply
Scope check_attributes
Do not apply
Apply, with the check's own attributes on top
Checks that run their own SQL ignore the scope filter, as they ignore the top-level filter: a metric check with query, a failed_rows check with query or keys_query, and a group_by check. A schema check reads no rows, so the scope filter does not change its result. In a scope, only its identity, its check path and its attributes change.
For reconciliation checks, which apply the scope
filterto the target side, see Filters in a contract scope. For failed rows, see Failed Rows check.
Identity and check paths of scoped checks
The scope key is part of a check's identity. The same check in two scopes is two checks in Soda Cloud, each with its own history.
The check path of a scoped check starts with its scope: scope.<key>:<path>. In the example above, the missing check on id in the scope eu has the check path scope.eu:columns.id.checks.missing, while the base missing check keeps columns.id.checks.missing.
Learn how to select checks by path in Check paths in a contract scope.
Scoped check execution
soda contract verify without a check filter runs the base checks and the checks of every scope. To run one scope, or only the base checks, filter on scope:
Learn more in Contract scope filters.
Without the soda-scopes package, Soda runs only the base checks. The scoped checks come back as not evaluated, in the CLI output and in the results sent to Soda Cloud, and Soda logs one error with their number and scopes:
The command then exits with code 3, so a run with checks that did not run never looks like a run that passed. A scoped check that a check filter leaves out comes back as excluded and logs no error.
In the Python API, the scope attribute of a Check holds its scope key, and None for a base check.
Last updated
Was this helpful?
