Skip to navigation

nemoguardrails.library.sensitive_data_detection.actions

View as MarkdownOpen in Claude

Module Contents

Classes

NameDescription
_DetectionExecutorKeep Presidio work out of the event loop’s shared thread pool.

Functions

NameDescription
_create_analyzerCreate an analyzer with the installed spaCy model.
_get_ad_hoc_recognizersHelper to compute the ad hoc recognizers for a config.
_get_analyzerReuse one analyzer per threshold, including concurrent cold starts.
_mask_sensitive_data_outcome-
_sensitive_data_detection_outcome-
detect_sensitive_dataChecks whether the provided text contains any sensitive data.
mask_sensitive_dataChecks whether the provided text contains any sensitive data.

Data

_T

_analyzer_init_lock

_detection_executor

log

API

class nemoguardrails.library.sensitive_data_detection.actions._DetectionExecutor()

Bases: ThreadPoolExecutor

Keep Presidio work out of the event loop’s shared thread pool.

nemoguardrails.library.sensitive_data_detection.actions._DetectionExecutor.run(
async

Offload work with the caller’s context and standard future cancellation.

nemoguardrails.library.sensitive_data_detection.actions._create_analyzer(
score_threshold: float = 0.4
)

Create an analyzer with the installed spaCy model.

nemoguardrails.library.sensitive_data_detection.actions._get_ad_hoc_recognizers(
sdd_config: nemoguardrails.rails.llm.config.SensitiveDataDetection
)

Helper to compute the ad hoc recognizers for a config.

nemoguardrails.library.sensitive_data_detection.actions._get_analyzer(
score_threshold: float = 0.4
)

Reuse one analyzer per threshold, including concurrent cold starts.

nemoguardrails.library.sensitive_data_detection.actions._mask_sensitive_data_outcome(
source: str,
original_text: str,
masked_text: str
nemoguardrails.library.sensitive_data_detection.actions._sensitive_data_detection_outcome(
has_sensitive_data: bool
nemoguardrails.library.sensitive_data_detection.actions.detect_sensitive_data(
source: str,
text: str,
config: nemoguardrails.RailsConfig,
kwargs = {}
async

Checks whether the provided text contains any sensitive data.

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 sensitive data has been detected, RailOutcome.allow() otherwise.

nemoguardrails.library.sensitive_data_detection.actions.mask_sensitive_data(
source: str,
text: str,
config: nemoguardrails.RailsConfig
async

Checks whether the provided text contains any sensitive data.

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

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

nemoguardrails.library.sensitive_data_detection.actions._T = TypeVar('_T')
nemoguardrails.library.sensitive_data_detection.actions._analyzer_init_lock = Lock()
nemoguardrails.library.sensitive_data_detection.actions._detection_executor = _DetectionExecutor(thread_name_prefix='presidio-detection')
nemoguardrails.library.sensitive_data_detection.actions.log = logging.getLogger(__name__)