nemoguardrails.library.privateai.actions

View as Markdown

PII detection using Private AI.

Module Contents

Functions

NameDescription
detect_piiChecks whether the provided text contains any PII.
detect_pii_mappingMapping for detect_pii.
mask_piiMasks any detected PII in the provided text.

Data

log

API

nemoguardrails.library.privateai.actions.detect_pii(
source: str,
text: str,
config: nemoguardrails.RailsConfig,
kwargs = {}
)
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 True if PII is detected, False otherwise.

Raises:

  • ValueError: If PAI_API_KEY is missing when using cloud API or if the response is invalid.
nemoguardrails.library.privateai.actions.detect_pii_mapping(
result: bool
) -> bool

Mapping for detect_pii.

Since the function returns True when PII is detected, we block if result is True.

nemoguardrails.library.privateai.actions.mask_pii(
source: str,
text: str,
config: nemoguardrails.RailsConfig
)
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:

The altered text with PII masked.

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__)