policy_match_rules

The following methods allow for interaction with the Zscaler AI Guard Policy Match Rules API endpoints. Includes listing, creating, updating, and deleting policy match rules, and retrieving a rule by ID or name.

Methods are accessible via aiguard.policy_match_rules

Copyright (c) 2023, Zscaler Inc.

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

class PolicyMatchRulesAPI

Bases: APIClient

A Client object for the AI Guard Policy Match Rules resource.

add_rule(**kwargs)

Creates a new policy match rule.

Parameters:
  • name (str) – The name of the policy match rule.

  • **kwargs – Optional keyword args.

Keyword Arguments:
  • policy_id (str) – The policy id for this policy match rule.

  • enabled (bool) – Indicates whether the policy match rule is enabled.

  • rule_order (str) – The rule order for this policy match rule.

  • version (str) – The version for this policy match rule.

  • match_criteria (str) – The match criteria for this policy match rule.

Returns:

A tuple containing the newly added PolicyMatchRules instance, response, and error.

Return type:

tuple

Examples

Add a new policy match rule. policyId, applicationId and applicationCredentialsIds must reference existing resources – create the detection policy, the LLM application and the application credential first and reuse the ids returned by those calls:

>>> added_rule, _, error = client.aiguard.policy_match_rules.add_rule(
...     policyId=2916,
...     name="PolicyRule01",
...     enabled=True,
...     ruleOrder=2,
...     matchCriteria={
...         "llmApplications": [
...             {
...                 "applicationId": 647,
...                 "applicationCredentialsIds": [1075],
...             }
...         ],
...         "type": "DAS_APPLICATION",
...     },
... )
>>> if error:
...     print(f"Error adding policy match rule: {error}")
...     return
... print(f"Policy match rule added successfully: {added_rule.as_dict()}")
delete_rule(rule_id)

Deletes the specified policy match rule.

Parameters:

rule_id (int) – The unique identifier for the policy match rule.

Returns:

A tuple containing the response object and error (if any).

Return type:

tuple

Examples

Delete a policy match rule:

>>> _, _, error = client.aiguard.policy_match_rules.delete_rule(1013)
>>> if error:
...     print(f"Error deleting policy match rule: {error}")
...     return
... print(f"Policy match rule deleted successfully.")
get_rule(rule_id)

Fetches a specific policy match rule by ID.

Parameters:

rule_id (int) – The unique identifier for the policy match rule.

Returns:

A tuple containing (PolicyMatchRules instance, Response, error).

Return type:

tuple

Examples

Print a specific policy match rule:

>>> fetched_rule, _, error = client.aiguard.policy_match_rules.get_rule(1013)
>>> if error:
...     print(f"Error fetching policy match rule by ID: {error}")
...     return
... print(f"Fetched policy match rule by ID: {fetched_rule.as_dict()}")
get_rule_by_name(name)

Fetches a specific policy match rule by name.

Parameters:

name (str) – The name of the policy match rule.

Returns:

A tuple containing (PolicyMatchRules instance, Response, error).

Return type:

tuple

Examples

Print a specific policy match rule by name:

>>> fetched_rule, _, error = client.aiguard.policy_match_rules.get_rule_by_name('Rule01')
>>> if error:
...     print(f"Error fetching policy match rule by name: {error}")
...     return
... print(f"Fetched policy match rule by name: {fetched_rule.as_dict()}")
list_rules(query_params=None)

Lists the policy match rules configured in your organization.

Parameters:

{dict} (query_params) – Map of query parameters for the request.

Returns:

A tuple containing (list of PolicyMatchRules instances, Response, error)

Return type:

tuple

Examples

List policy match rules:

>>> rule_list, _, error = client.aiguard.policy_match_rules.list_rules()
>>> if error:
...     print(f"Error listing policy match rules: {error}")
...     return
... print(f"Total policy match rules found: {len(rule_list)}")
... for rule in rule_list:
...     print(rule.as_dict())

Client-side filtering with JMESPath:

The response object supports client-side filtering and projection via resp.search(expression). See the JMESPath documentation for expression syntax.

update_rule(rule_id, **kwargs)

Updates information for the specified policy match rule.

Parameters:

rule_id (int) – The unique identifier for the policy match rule.

Keyword Arguments:
  • name (str) – The name of the policy match rule.

  • policy_id (str) – The policy id for this policy match rule.

  • enabled (bool) – Indicates whether the policy match rule is enabled.

  • rule_order (str) – The rule order for this policy match rule.

  • version (str) – The version for this policy match rule.

  • match_criteria (str) – The match criteria for this policy match rule.

Returns:

A tuple containing the updated PolicyMatchRules instance, response, and error.

Return type:

tuple

Examples

Update an existing policy match rule. The update replaces the rule, so the match criteria are sent in full:

>>> updated_rule, _, error = client.aiguard.policy_match_rules.update_rule(
...     rule_id=1013,
...     policyId=2916,
...     name="PolicyRule01_Updated",
...     enabled=True,
...     ruleOrder=2,
...     matchCriteria={
...         "llmApplications": [
...             {
...                 "applicationId": 647,
...                 "applicationCredentialsIds": [1075],
...             }
...         ],
...         "type": "DAS_APPLICATION",
...     },
... )
>>> if error:
...     print(f"Error updating policy match rule: {error}")
...     return
... print(f"Policy match rule updated successfully: {updated_rule.as_dict()}")