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.
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: RailOutcome
RailOutcome.block() if PII is detected or 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 a blocking outcome).
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: RailOutcome
A transform outcome with PII masked. The transform uses
Raises:
ValueError: Only ifsourceis not one of the allowed flows. Provider/network failures are caught and treated as fail-closed.