Set up policies

This page gives a brief overview of folders and explains how to manage documents using folders.

Policy Engine and rules

In Document Warehouse, Policy Engine let users to define and execute common operations on documents (for example, validate or update) while creating or updating documents.

Rules and RuleSet

A Rule at a high level refers to a user-defined configuration that specifies the following:

  • what triggers the rules checking,
  • which condition is evaluated, and
  • what actions are run when the condition is satisfied.

Along with these specifications, a rule includes information of the description, source, target and triggering condition.

A logical collection of rules is called a RuleSet. For example, Rules operating on the same schema can be grouped together into a single RuleSet. Customers can define multiple RuleSets.

Rules are useful for automatically triggering predefined actions, while creating or updating documents.

A Rule consists of three main things:

  • TriggerType: Event on which the rule check should be initiated. Create and Update are the supported trigger types.
  • Rule Condition: The condition that is evaluated after a certain trigger type is detected. Conditions can be expressed using Common Expression Language (CEL). Each condition should evaluate to boolean output.
  • Actions: Set of steps that are executed when the rule is satisfied. When a rule condition is evaluated as true, then the corresponding action (configured in the rule) is executed. The following are the high-level details about specific actions implemented in Document Warehouse:
    • Data Validation action: Action that enables validating specific fields in the document during document creation or update.
    • Data Update action: Action that enables updating specific fields in the document during document creation or update. Such updates are run when the rule condition is satisfied.
    • Delete Document Action: Action that enables deleting the document during document update when certain fields meet the deletion criteria defined using rule conditions.
    • Folder inclusion action: Action that automatically adds a new document (or updated document) under specific folders. Such folders can be specified directly using their name.
    • Remove from folder action: Action that automatically removes a new document from given folders when a rule-level condition is satisfied.
    • Access Control Action: Action that allows updating the access control lists (groups and user bindings) during document creation. Such updates are run when the rule condition is satisfied.
    • Publish action: Action that publishes specific messages to the user's Pub/Sub channel when a rule-level condition is satisfied.

Manage RuleSets

Document Warehouse provides APIs to manage RuleSets (Create, Get, Update, Delete, List). This section provides samples for configuring different types for rules.

Create a RuleSet

To create a rule-set, do the following:

REST

Request:

# Create a RuleSet for data validation.
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/ruleSets \
-d '{
  "rules": [
    {
      "trigger_type": "ON_CREATE",
      "condition": "documentType == \'W9\' && STATE ==\'CA\'",
      "actions": {
        "data_validation": {
          "conditions": {
            "NAME": "NAME != \'\'",
            "FILING_COST": "FILING_COST > 10.0"
          }
        }
      },
      "enabled": true
    }
  ],
  "description": "W9: Basic validation check rules."
}'

Response

{
  "description": "W9: Basic validation check rules.",
  "name": "RULE_SET_NAME",
  "rules": [
    {
      "actions": [
        {
          "actionId": "de0e6b84-106b-44ba-b1c4-0b3ad6ddc719",
          "dataValidation": {
            "conditions": {
              "FILING_COST": "FILING_COST > 10.0",
              "NAME": "NAME != ''"
            }
          }
        }
      ],
      "condition": "documentType == 'W9' && STATE =='CA'",
      "enabled": true,
      "triggerType": "ON_CREATE"
    }
  ]
}

Python

For more information, see the Document AI Warehouse Python API reference documentation.

To authenticate to Document AI Warehouse, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


from google.cloud import contentwarehouse

# TODO(developer): Uncomment these variables before running the sample.
# project_number = "YOUR_PROJECT_NUMBER"
# location = "us" # Format is 'us' or 'eu'


def create_rule_set(project_number: str, location: str) -> None:
    # Create a client
    client = contentwarehouse.RuleSetServiceClient()

    # The full resource name of the location, e.g.:
    # projects/{project_number}/locations/{location}
    parent = client.