nemoguardrails.library.privateai.actions

View as Markdown

PII detection using Private AI.

Module Contents

Functions

NameDescription
_mask_pii_outcome-
_pii_detection_outcome-
detect_piiChecks whether the provided text contains any PII.
mask_piiMasks any detected PII in the provided text.

Data

log

API

nemoguardrails.library.privateai.actions._mask_pii_outcome(
source: str,
original_text: str,
masked_text: str
) -> nemoguardrails.actions.rail_outcome.RailOutcome
nemoguardrails.library.privateai.actions._pii_detection_outcome(
has_pii: bool
) -> nemoguardrails.actions.rail_outcome.RailOutcome
nemoguardrails.library.privateai.actions.detect_pii(
source: str,
text: str,
config: nemoguardrails.RailsConfig,
http_client: nemoguardrails.http.HTTPClient | None = None,
kwargs = {}
) -> nemoguardrails.actions.rail_outcome.RailOutcome
async

Checks whether the provided text contains any PII.

Args source: The source for the text, i.e. “input”, “output”, “retrieval”. text: The text to check. config: The rails configuration object.

Returns RailOutcome.block() if PII is detected, RailOutcome.allow() otherwise.

Raises:

  • ValueError: If PAI_API_KEY is missing when using cloud API or if the response is invalid.
nemoguardrails.library.privateai.actions.mask_pii(
source: str,
text: str,
config: nemoguardrails.RailsConfig,
http_client: nemoguardrails.http.HTTPClient | None = None
) -> nemoguardrails.actions.rail_outcome.RailOutcome
async

Masks any detected PII in the provided text.

Parameters:

source
str

The source for the text, i.e. “input”, “output”, “retrieval”.

text
str

The text to check.

config
RailsConfig

The rails configuration object.

Returns: RailOutcome

RailOutcome.transform() with the altered text if it changed, RailOutcome.allow() otherwise.

Raises:

  • ValueError: If PAI_API_KEY is missing when using cloud API or if the response is invalid.
nemoguardrails.library.privateai.actions.log = logging.getLogger(__name__)