nemoguardrails.library.regex.actions
Module Contents
Classes
Functions
Data
API
Bases: typing.TypedDict
Match text against a pattern group’s pre-compiled patterns, logging as each miss/hit occurs.
Extracted from detect_regex_pattern’s own matching loop so detect_tool_call_regex_pattern and detect_tool_result_regex_pattern don’t duplicate it. detect_regex_pattern’s inline loop below is left as-is for now. TODO: refactor it to call this helper too.
Checks whether the provided text matches any forbidden regex pattern.
Parameters:
The source for the text, i.e. “input”, “output”, “retrieval”.
The text to check.
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.
Checks a tool call’s arguments against that tool’s regex patterns.
Parameters:
Fixed per surface, always “tool_call”.
ToolCall — The tool call to check.
Optional[ Tool ] — The declared tool, used only by @tool_call_validation to check
the call’s arguments against its schema before this function runs.
RailsConfig — The rails configuration object.
Narrows the checked arguments to one named argument, from
$argument= on the flow. Absent, the full arguments dict is checked.
Returns: RailOutcome
RailOutcome with RegexDetectionResult fields in metadata (see detect_regex_pattern).
Checks a tool result’s content against that tool’s regex patterns.
Parameters:
Fixed per surface, always “tool_result”.
ToolCall — The prior call this result answers, used to resolve the tool name.
ToolResult — The tool result to check.
RailsConfig — The rails configuration object.
Returns: RailOutcome
RailOutcome with RegexDetectionResult fields in metadata (see detect_regex_pattern).