policy_detection

The following methods allow for interaction with the Zscaler AI Guard Policy Detection API endpoints. Includes executing a detection policy and resolving-and-executing a detection policy against content.

Warning

These endpoints are only available through the legacy AI Guard client.

The policy detection endpoints (/v1/detection/execute-policy and /v1/detection/resolve-and-execute-policy) are not exposed through OneAPI. They must be called with LegacyAIGuardClient, which authenticates with an AI Guard API key against https://api.<cloud>.zseclipse.net.

Every other AI Guard resource – detection policies, policy match rules, LLM providers, LLM applications and their credentials – is OneAPI only and is reached with ZscalerClient.

Methods are accessible via aiguard.policy_detection on a LegacyAIGuardClient:

from zscaler.oneapi_client import LegacyAIGuardClient

with LegacyAIGuardClient({"api_key": "<api key>", "cloud": "us1"}) as client:
    result, _, err = client.aiguard.policy_detection.resolve_and_execute_policy(
        content="User prompt or AI response to scan",
        direction="IN",
    )

The API key may also be supplied through the AIGUARD_API_KEY environment variable (AIGUARD_CLOUD for the cloud, AIGUARD_OVERRIDE_URL to override the base URL).

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 PolicyDetectionAPI

Bases: APIClient

API client for AI Guard Policy Detection operations.

Warning

These endpoints are legacy only. /v1/detection/execute-policy and /v1/detection/resolve-and-execute-policy are not exposed through OneAPI, so this interface is reached with LegacyAIGuardClient (AI Guard API key against https://api.<cloud>.zseclipse.net) rather than ZscalerClient.

All other AI Guard resources are OneAPI only.

Examples

>>> from zscaler.oneapi_client import LegacyAIGuardClient
>>> with LegacyAIGuardClient({"api_key": "<api key>", "cloud": "us1"}) as client:
...     result, _, err = client.aiguard.policy_detection.resolve_and_execute_policy(
...         content="User prompt or AI response to scan",
...         direction="IN",
...     )
execute_policy(content, direction, policy_id=None, transaction_id=None)

Executes a policy detection with a specific policy ID.

Parameters:
  • content (str) – The content to scan

  • direction (str) – The direction of the content (‘IN’ or ‘OUT’)

  • policy_id (int, optional) – The policy ID to execute against

  • transaction_id (str, optional) – Optional transaction ID for tracking

Returns:

Tuple of (result, response, error)

Return type:

APIResult[ExecuteDetectionsPolicyResponse]

Examples

Minimal payload (content + direction):
>>> result, resp, err = client.zguard.policy_detection.execute_policy(
...     content="User prompt or AI response to scan",
...     direction="IN"
... )
With optional policy_id and transaction_id:
>>> result, resp, err = client.zguard.policy_detection.execute_policy(
...     content="Content to scan",
...     direction="OUT",
...     policy_id=12345,
...     transaction_id="txn-abc-123"
... )
resolve_and_execute_policy(content, direction, transaction_id=None)

Resolves and executes a policy detection (automatic policy selection).

Parameters:
  • content (str) – The content to scan

  • direction (str) – The direction of the content (‘IN’ or ‘OUT’)

  • transaction_id (str, optional) – Optional transaction ID for tracking

Returns:

Tuple of (result, response, error)

Return type:

APIResult[ResolveAndExecuteDetectionsPolicyResponse]

Examples

Minimal payload (content + direction):
>>> result, resp, err = client.zguard.policy_detection.resolve_and_execute_policy(
...     content="User prompt or AI response to scan",
...     direction="IN"
... )
With optional transaction_id:
>>> result, resp, err = client.zguard.policy_detection.resolve_and_execute_policy(
...     content="Content to scan",
...     direction="OUT",
...     transaction_id="txn-abc-123"
... )