nemoguardrails.library.regex.actions

View as Markdown

Module Contents

Classes

NameDescription
RegexDetectionResult-

Functions

NameDescription
_regex_outcome-
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_outcome(
source: str,
result: nemoguardrails.library.regex.actions.RegexDetectionResult
) -> nemoguardrails.actions.rail_outcome.RailOutcome
nemoguardrails.library.regex.actions.detect_regex_pattern(
source: str,
text: str,
config: nemoguardrails.RailsConfig,
kwargs = {}
) -> nemoguardrails.actions.rail_outcome.RailOutcome
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: RailOutcome

RailOutcome with RegexDetectionResult fields in metadata:

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