nemoguardrails.library.gliner.actions
PII detection using GLiNER.
Module Contents
Functions
Data
API
Mask detected entities in text with their labels.
Parameters:
Original text
List of entity dictionaries with ‘value’, ‘suggested_label’, ‘start_position’, ‘end_position’ keys
Returns: str
Text with entities replaced by [LABEL] placeholders
Resolve the GLiNER API key from the configured env var, logging a warning if the env var is named but not set in the environment.
Mapping for 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 GLiNER.
Parameters:
The source for the text, i.e. “input”, “output”, “retrieval”.
The text to check.
The rails configuration object.
Returns:
True if PII is detected, False otherwise.
Raises:
ValueError: If the response is invalid or source is not valid.
Masks any detected PII in the provided text using GLiNER.
Parameters:
The source for the text, i.e. “input”, “output”, “retrieval”.
The text to check.
The rails configuration object.
Returns:
The altered text with PII masked.
Raises:
ValueError: If the response is invalid or source is not valid.