nemoguardrails.library.polygraf.actions
PII detection using Polygraf.
Module Contents
Functions
Data
API
Split Polygraf entities into safe spans and report whether any span is unsafe enough to require failing closed.
Parameters:
Raw entity records returned by Polygraf.
The configured entity-type filter (or None to
accept every Polygraf-reported type).
Length of the original payload, used to validate that integer offsets actually point inside the text.
Returns: List[Tuple[int, int, str]]
(safe_spans, has_malformed_selected)
Return a PII-free structural description of an entity for logging.
Strict integer check.
bool is a subclass of int in Python, so a plain isinstance(x, int)
would accept True/False as valid offsets. Explicitly reject booleans
so a Polygraf response cannot smuggle bogus span coordinates past validation.
Resolve the Polygraf config and per-source entity filter, validating source.
Mapping for polygraf_detect_pii.
Since the function returns True when PII is detected, we block if result is True.
Checks whether the provided text contains any PII using Polygraf.
Parameters:
The source for the text, i.e. “input”, “output”, “retrieval”.
The text to check.
The rails configuration object.
Returns: bool
True if PII is detected (or if the detection cannot complete safely),
Raises:
ValueError: Only ifsourceis not one of the allowed flows. Provider/network failures are caught and treated as fail-closed (the action returns True so the rail blocks the message).
Masks any detected PII in the provided text using Polygraf.
Parameters:
The source for the text, i.e. “input”, “output”, “retrieval”.
The text to check.
The rails configuration object.
Returns: str
The altered text with PII masked. Returns FAILSAFE_MASK_PLACEHOLDER
Raises:
ValueError: Only ifsourceis not one of the allowed flows. Provider/network failures are caught and treated as fail-closed.