Rule libraries in Knowledge Catalog (formerly Dataplex Universal Catalog) let you create and manage custom GoogleSQL rule templates so you can reuse data quality rules across multiple tables. Centralizing these definitions helps you update business logic in one place instead of duplicating SQL across individual scans.
For conceptual background, SQL parameter syntax, and aspect schemas, see About reusing data quality rules. After you create templates, you can apply them to catalog entries and data quality scans.
Limitations
The following limitations apply when creating rule libraries and custom rule templates:
- You can't change a rule library's location after you create it.
- Each custom rule template supports one SQL query in
sqlCollection. - A data quality scan or catalog entry can reference a custom rule template
only if the template is in the same region or in the
globallocation.
Before you begin
This document is for data stewards and data engineers who author and maintain standardized validation logic. Follow these tasks in order:
- Browse system rule templates to check whether a Google-managed template already meets your requirements.
- If you need custom SQL logic, then create a rule library to store your organization's templates, create custom rule templates inside it, and verify the saved templates.
- Apply your templates to scans or catalog entries to start validating BigQuery tables.
Before you start, review the following concepts and complete the setup requirements:
- Understand how rule libraries, templates, and scans fit together in About reusing data quality rules.
- Review parameter and assertion rules in SQL query syntax for rule templates.
Enable the Dataplex API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the serviceusage.services.enable permission. If you
created the project, then you likely already have this permission through the
Owner role (roles/owner). Otherwise, you can get this permission through the
Service Usage Admin role (roles/serviceusage.serviceUsageAdmin).
Learn how to grant roles.
Required roles
To get the permissions that you need to create, view, list, update, and delete rule libraries and custom rule templates, ask your administrator to grant you the following IAM roles on the project or entry group that stores your rule library:
-
Create, update, and delete rule libraries:
Dataplex Catalog Editor (
roles/dataplex.catalogEditor) -
Create, view, list, update, and delete custom rule templates using the API or direct entry-group path:
Dataplex Entry and EntryLink Owner (
roles/dataplex.entryOwner)
For more information about granting roles, see Manage access to projects, folders, and organizations.
These predefined roles contain the permissions required to create, view, list, update, and delete rule libraries and custom rule templates. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to create, view, list, update, and delete rule libraries and custom rule templates:
-
Create and manage rule libraries:
-
dataplex.entryGroups.create -
dataplex.entryGroups.get -
dataplex.entryGroups.list -
dataplex.entryGroups.update -
dataplex.entryGroups.delete
-
-
Create, update, and delete custom rule templates:
-
dataplex.entries.create -
dataplex.entries.update -
dataplex.entries.delete -
dataplex.entryGroups.useDataQualityRuleTemplateEntry -
dataplex.entryGroups.useDataQualityRuleTemplateAspect
-
-
View and list rule templates:
-
dataplex.entries.get -
dataplex.entries.getData -
dataplex.entries.list
-
You might also be able to get these permissions with custom roles or other predefined roles.
The Dataplex Catalog Editor (roles/dataplex.catalogEditor) role also includes
all permissions needed to create, view, list, update, and delete custom rule
templates. To browse Rule libraries > Custom in the
Google Cloud console, you also need the dataplex.entryGroups.list permission on
the project, which isn't included in roles/dataplex.entryOwner. You can grant
dataplex.entryGroups.list through Dataplex Catalog Viewer
(roles/dataplex.catalogViewer), Dataplex Entry Group Owner
(roles/dataplex.entryGroupOwner), or Dataplex Catalog Editor
(roles/dataplex.catalogEditor). For read-only access to view and list custom
rule templates without write or delete permissions, grant a
custom role with only the
dataplex.entries.get, dataplex.entries.getData, and dataplex.entries.list
permissions.
Browse system rule templates
Before authoring custom SQL templates, check the Google-managed system rule
templates in the global rule-library entry group to see whether a predefined
template meets your validation requirements. For descriptions of every
predefined template, see
System rule templates list.
Select one of the following options:
Console
In the Google Cloud console, go to the Data profiling & quality page.
Click Rule libraries > System.
To view all available system rule templates, click rule-library.
Optional: To inspect a template's SQL logic, input parameters, and capabilities, click the template name.
REST
To list available system rule templates, send a GET request to the
projects.locations.entryGroups.entries.list
method:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://dataplex.googleapis.com/v1/projects/dataplex-templates/locations/global/entryGroups/rule-library/entries"
The response lists the system rule template entries in the global
rule-library entry group, including each template's name,
entrySource.displayName, and entrySource.description.
Create a rule library
If no system template covers your validation logic, then create a rule library
entry group to organize and store your organization's custom rule templates.
Choose the same region as your target scans—or select global to share
templates across regions—because you can't change the location after you create
the library. For rule library ID rules, see
Resource naming conventions.
Select one of the following options:
Console
In the Google Cloud console, go to the Data profiling & quality page.
Click Rule libraries > Custom, and then click Create.
In the Create rule library pane, complete the following fields:
- Optional: In the Display name field, enter a display name.
- In the Rule library ID field, enter a unique ID.
- Optional: In the Description field, enter a description.
- In the Location menu, select a region or global. You can't change this location after creation.
- Optional: To group related resources, add key-value labels.
To create the library, click Save.
Verify that the rule library appears in the Custom list.
REST
To create a rule library, send a POST request to the
projects.locations.entryGroups.create
method with the required goog-dataplex-entry-group-type: rule_library
label:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/entryGroups?entryGroupId=RULE_LIBRARY_ID" \
-d '{
"displayName": "DISPLAY_NAME",
"description": "DESCRIPTION",
"labels": {
"goog-dataplex-entry-group-type": "rule_library"
}
}'
Replace the following:
PROJECT_ID: the Google Cloud project ID (for example,test-project).LOCATION: the region orgloballocation for the rule library (for example,us-central1).RULE_LIBRARY_ID: a unique ID for the rule library (for example,finance-rule-library).DISPLAY_NAME: an optional human-readable name for the rule library.DESCRIPTION: an optional description of the rule library.
Terraform
To create a rule library, use the
google_dataplex_entry_group
resource in the Terraform Registry:
resource "google_dataplex_entry_group" "rule_library" {
project = "PROJECT_ID"
location = "LOCATION"
entry_group_id = "RULE_LIBRARY_ID"
display_name = "DISPLAY_NAME"
description = "DESCRIPTION"
labels = {
"goog-dataplex-entry-group-type" = "rule_library"
}
}
Replace the following:
PROJECT_ID: the Google Cloud project ID (for example,test-project).LOCATION: the region orgloballocation for the rule library (for example,us-central1).RULE_LIBRARY_ID: a unique ID for the rule library (for example,finance-rule-library).DISPLAY_NAME: an optional human-readable name for the rule library.DESCRIPTION: an optional description of the rule library.
Create a custom rule template
After creating a rule library, add custom rule templates inside it to define parameterized GoogleSQL checks that teams can reuse across scans and catalog entries. For query guidelines and system parameters, see SQL query syntax for rule templates. For ID requirements, dimensions, and aspect fields, see Resource naming conventions, Data quality dimensions, and Rule template aspect fields.
Select one of the following options:
Console
In the Google Cloud console, go to the Data profiling & quality page.
Click Rule libraries > Custom.
Click the rule library where you want to add a template, and then click Create.
In the Create rule template pane, enter the template metadata:
- Optional: In the Template name field, enter a name for the template.
- In the Template ID field, enter a unique ID.
- Optional: In the Description field, enter a description.
- In the Dimension menu, select a data quality dimension.
In the SQL query field, enter a query that returns invalid rows without a trailing semicolon. For example, the following query checks whether column values fall between two bounds:
SELECT * FROM ${data()} WHERE NOT ((${column()} >= ${param(min_value)} AND ${column()} <= ${param(max_value)}) IS TRUE)Optional: To let referencing rules configure pass-ratio thresholds, select Support threshold.
Optional: To let referencing rules ignore
NULLvalues, first select Support threshold, and then select Support ignore null.In the Input parameters section, click Add input parameter, and then enter a name, description, and optional default value for each parameter in your query (for example,
min_valueandmax_value).To create the template, click Save.
REST
To create a custom rule template, send a POST request to the
projects.locations.entryGroups.entries.create
method with the data-quality-rule-template entry type and aspect:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/entryGroups/RULE_LIBRARY_ID/entries?entryId=TEMPLATE_ID" \
-d '{
"entryType": "projects/dataplex-types/locations/global/entryTypes/data-quality-rule-template",
"entrySource": {
"displayName": "DISPLAY_NAME",
"description": "DESCRIPTION"
},
"aspects": {
"dataplex-types.global.data-quality-rule-template": {
"data": {
"dimension": "VALIDITY",
"sqlCollection": [
{
"query": "SELECT t.* FROM ${data()} AS t LEFT JOIN `${param(reference_table)}` AS s ON t.${column()} = s.`${param(reference_column)}` WHERE s.`${param(reference_column)}` IS NULL"
}
],
"inputParameters": {
"reference_table": {
"description": "Reference table in PROJECT_ID.DATASET_ID.TABLE_ID format."
},
"reference_column": {
"description": "Primary key column in the reference table."
}
},
"capabilities": ["THRESHOLD"]
}
}
}
}'
Replace the following:
PROJECT_ID: the Google Cloud project ID (for example,test-project).LOCATION: the location of the rule library (for example,us-central1).RULE_LIBRARY_ID: the ID of the rule library entry group.TEMPLATE_ID: a unique ID for the rule template (for example,foreign-key-check).DISPLAY_NAME: a human-readable display name for the template.DESCRIPTION: a description of what the template validates.
Terraform
To create a custom rule template, use the
google_dataplex_entry
resource in the Terraform Registry. Escape ${...} parameters as $${...}
so Terraform doesn't interpolate them as HCL variables, and use
655216118709 (the project number for dataplex-types) in entry_type and
aspect_key:
resource "google_dataplex_entry" "rule_template" {
project = "PROJECT_NUMBER"
location = "LOCATION"
entry_group_id = "RULE_LIBRARY_ID"
entry_id = "TEMPLATE_ID"
entry_type = "projects/655216118709/locations/global/entryTypes/data-quality-rule-template"
entry_source {
display_name = "DISPLAY_NAME"
description = "DESCRIPTION"
}
aspects {
aspect_key = "655216118709.global.data-quality-rule-template"
aspect {
data = jsonencode({
dimension = "VALIDITY"
sqlCollection = [
{
query = "SELECT t.* FROM $${data()} AS t LEFT JOIN `$${param(reference_table)}` AS s ON t.$${column()} = s.`$${param(reference_column)}` WHERE s.`$${param(reference_column)}` IS NULL"
}
]
inputParameters = {
reference_table = {
description = "Reference table in PROJECT_ID.DATASET_ID.TABLE_ID format."
}
reference_column = {
description = "Primary key column in the reference table."
}
}
capabilities = ["THRESHOLD"]
})
}
}
}
Replace the following:
PROJECT_NUMBER: the Google Cloud project number.LOCATION: the location of the rule library (for example,us-central1).RULE_LIBRARY_ID: the ID of the rule library entry group.TEMPLATE_ID: a unique ID for the rule template (for example,foreign-key-check).DISPLAY_NAME: a human-readable display name for the template.DESCRIPTION: a description of what the template validates.
View and list custom rule templates
Before teams reference your custom rule templates in scans or catalog entries, inspect the templates to verify that your SQL logic, parameters, and capabilities are saved as expected.
Select one of the following options:
Console
In the Google Cloud console, go to the Data profiling & quality page.
Click Rule libraries > Custom.
Click the rule library that contains your templates.
In the Rule templates list, review the listed template names and descriptions.
To view the dimension, SQL query, input parameters, and capabilities, click a template name.
REST
To inspect a specific custom rule template including its aspect data, send a
GET request to the
projects.locations.entryGroups.entries.get
method with view=ALL. To list all templates in a library, use
projects.locations.entryGroups.entries.list.
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/entryGroups/RULE_LIBRARY_ID/entries/TEMPLATE_ID?view=ALL"
Replace the following:
PROJECT_ID: the Google Cloud project ID.LOCATION: the location of the rule library.RULE_LIBRARY_ID: the ID of the rule library entry group.TEMPLATE_ID: the ID of the rule template to inspect.
Verify the following fields in the response:
| Field | What to check |
|---|---|
name |
Full resource name used in templateReference.name when binding rules. |
aspects.*.data.dimension |
Default data quality dimension for rules referencing this template. |
aspects.*.data.sqlCollection |
Active parameterized SQL query evaluated during scan runs. |
aspects.*.data.capabilities |
Enabled rule-level capabilities (THRESHOLD or IGNORE_NULL). |
Update a custom rule template
When your business validation requirements change, update the custom rule
template once in your rule library. Every scan referencing that template uses
the revised SQL logic, parameters, or capabilities on its next run. If you
rename or add required input parameters without a defaultValue, then existing
rules referencing the template fail until you update their parameter values.
Select one of the following options:
Console
In the Google Cloud console, go to the Data profiling & quality page.
Click Rule libraries > Custom.
Click the rule library that contains the template that you want to update.
In the Rule templates list, click the template name.
On the rule template details page, click Edit.
Update the template fields, and then click Save.
Verify that the updated SQL query and parameters appear on the template details page.
REST
To update a custom rule template, send a PATCH request to the
projects.locations.entryGroups.entries.patch
method with updateMask=aspects:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/entryGroups/RULE_LIBRARY_ID/entries/TEMPLATE_ID?updateMask=aspects" \
-d '{
"aspects": {
"dataplex-types.global.data-quality-rule-template": {
"data": {
"dimension": "VALIDITY",
"sqlCollection": [
{
"query": "SELECT * FROM ${data()} WHERE ${column()} IS NULL"
}
],
"capabilities": ["THRESHOLD"]
}
}
}
}'
Replace the following:
PROJECT_ID: the Google Cloud project ID.LOCATION: the location of the rule library.RULE_LIBRARY_ID: the ID of the rule library entry group.TEMPLATE_ID: the ID of the rule template to update.
Terraform
To update a custom rule template, modify the aspects block of the
google_dataplex_entry
resource and run terraform apply:
resource "google_dataplex_entry" "rule_template" {
project = "PROJECT_NUMBER"
location = "LOCATION"
entry_group_id = "RULE_LIBRARY_ID"
entry_id = "TEMPLATE_ID"
entry_type = "projects/655216118709/locations/global/entryTypes/data-quality-rule-template"
aspects {
aspect_key = "655216118709.global.data-quality-rule-template"
aspect {
data = jsonencode({
dimension = "VALIDITY"
sqlCollection = [
{
query = "SELECT * FROM $${data()} WHERE $${column()} IS NULL"
}
]
capabilities = ["THRESHOLD"]
})
}
}
}
Replace the following:
PROJECT_NUMBER: the Google Cloud project number.LOCATION: the location of the rule library.RULE_LIBRARY_ID: the ID of the rule library entry group.TEMPLATE_ID: the ID of the rule template to update.
Delete a custom rule template
When you retire a custom validation check that active scans or catalog entries no longer need, delete the template from your rule library. Removing retired templates prevents other teams from referencing obsolete logic.
Select one of the following options:
Console
In the Google Cloud console, go to the Data profiling & quality page.
Click Rule libraries > Custom.
Click the rule library that contains the template that you want to delete.
In the Rule templates list, click the template name.
Click Delete, and then click Delete again to confirm.
Verify that the template no longer appears in the Rule templates list.
REST
To delete a custom rule template, send a DELETE request to the
projects.locations.entryGroups.entries.delete
method:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/entryGroups/RULE_LIBRARY_ID/entries/TEMPLATE_ID"
Replace the following:
PROJECT_ID: the Google Cloud project ID.LOCATION: the location of the rule library.RULE_LIBRARY_ID: the ID of the rule library entry group.TEMPLATE_ID: the ID of the rule template to delete.
Troubleshoot
If you encounter errors while creating or updating rule templates, then check the following common causes:
- SQL syntax validation fails: remove any trailing semicolon (
;) from the query string, and verify that parameter names match case exactly between${param(PARAMETER_NAME)}andinputParameters. IGNORE_NULLcapability rejected: confirm thatcapabilitiesalso includesTHRESHOLD, becauseIGNORE_NULLrequiresTHRESHOLDand applies only to column-level rules.- Permission denied when saving a template: verify that you have the
Dataplex Catalog Editor (
roles/dataplex.catalogEditor) or Dataplex Entry and EntryLink Owner (roles/dataplex.entryOwner) role on the entry group. If you use a custom role, then verify that it includes thedataplex.entryGroups.useDataQualityRuleTemplateEntryanddataplex.entryGroups.useDataQualityRuleTemplateAspectpermissions.
What's next
- Attach rules to tables and glossary terms and run scans in Apply data quality rules and run scans.
- Explore all predefined checks in System rule templates list.
- Review architecture, SQL syntax, and aspect schemas in About reusing data quality rules.
- Automate rule deployments in Manage data quality rules as code with Terraform, Cloud Build, and GitHub.