nemoguardrails.library.regex.actions

View as Markdown

Module Contents

Classes

NameDescription
RegexDetectionResult-

Functions

NameDescription
_regex_blocked_mappingReturn True (blocked) when a regex match was found.
detect_regex_patternChecks whether the provided text matches any forbidden regex pattern.

Data

log

API

class nemoguardrails.library.regex.actions.RegexDetectionResult

Bases: typing.TypedDict

detections
List[str]
is_match
bool
text
str
nemoguardrails.library.regex.actions._regex_blocked_mapping(
result: nemoguardrails.library.regex.actions.RegexDetectionResult
) -> bool

Return True (blocked) when a regex match was found.

nemoguardrails.library.regex.actions.detect_regex_pattern(
source: str,
text: str,
config: nemoguardrails.RailsConfig,
kwargs = {}
) -> nemoguardrails.library.regex.actions.RegexDetectionResult
async

Checks whether the provided text matches any forbidden regex pattern.

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: RegexDetectionResult

A TypedDict containing:

  • is_match (bool): Whether any pattern matched.
  • text (str): The original text that was checked.
  • detections (List[str]): List of pattern strings that matched.
nemoguardrails.library.regex.actions.log = logging.getLogger(__name__)