Skip to navigation

nemoguardrails.library.zscaler_aiguard.actions

View as MarkdownOpen in Claude

Zscaler AI Guard integration for NeMo Guardrails.

Scans prompts and LLM responses using the Zscaler AI Guard DAS API via the zscaler-sdk-python SDK.

By default, uses resolve-and-execute-policy (automatic policy selection). Set AIGUARD_POLICY_ID to use execute-policy with a specific policy.

Required environment variables: AIGUARD_API_KEY - Zscaler AI Guard API key (Bearer token) AIGUARD_CLOUD - Cloud region, e.g. us1, us2, eu1 (default: us1)

Optional environment variables: AIGUARD_POLICY_ID - Specific policy ID to use (default: auto-resolved)

Module Contents

Classes

NameDescription
_MissingApiKeyError-

Functions

NameDescription
_build_block_messageBuild a human-readable block message with full context.
_get_attrAccess an attribute by name from either a dict or an object.
_get_sdk_clientLazily initialise the Zscaler AI Guard SDK client.
_outcome_metadata-
_scan_syncCall the AI Guard API synchronously (wrapped with asyncio.to_thread).
call_zscaler_aiguard_apiScan content using Zscaler AI Guard.

Data

_sdk_client

_sdk_client_cloud

log

API

class nemoguardrails.library.zscaler_aiguard.actions._MissingApiKeyError()

Bases: EnvironmentError

nemoguardrails.library.zscaler_aiguard.actions._build_block_message(
direction: str,
severity: str,
policy_name: str,
blocking_detectors: list,
transaction_id: typing.Optional[str] = None
) -> str

Build a human-readable block message with full context.

nemoguardrails.library.zscaler_aiguard.actions._get_attr(
obj,
name,
default = None
)

Access an attribute by name from either a dict or an object.

nemoguardrails.library.zscaler_aiguard.actions._get_sdk_client()

Lazily initialise the Zscaler AI Guard SDK client.

nemoguardrails.library.zscaler_aiguard.actions._outcome_metadata(
action_value: str,
severity: str,
policy_name: str,
transaction_id: typing.Optional[str],
detectors: dict[str, typing.Any],
blocking_detectors: list[str],
extra: typing.Any = {}
) -> dict[str, typing.Any]
nemoguardrails.library.zscaler_aiguard.actions._scan_sync(
content: str,
direction: str,
policy_id: typing.Optional[int] = None
)

Call the AI Guard API synchronously (wrapped with asyncio.to_thread).

nemoguardrails.library.zscaler_aiguard.actions.call_zscaler_aiguard_api(
text: typing.Optional[str] = None,
direction: str = 'IN',
policy_id: typing.Optional[int] = None,
kwargs = {}
async

Scan content using Zscaler AI Guard.

Parameters:

text
Optional[str]Defaults to None

Content to scan (user prompt or bot response).

direction
strDefaults to 'IN'

“IN” for user prompts, “OUT” for bot responses.

policy_id
Optional[int]Defaults to None

Optional policy ID. If provided, calls execute_policy instead of resolve_and_execute_policy. Can also be set via AIGUARD_POLICY_ID environment variable.

Returns: RailOutcome

The rail decision with the parsed AI Guard response as metadata.

nemoguardrails.library.zscaler_aiguard.actions._sdk_client = None
nemoguardrails.library.zscaler_aiguard.actions._sdk_client_cloud = None
nemoguardrails.library.zscaler_aiguard.actions.log = logging.getLogger(__name__)