nemoguardrails.guardrails.tool_rail_action

View as Markdown

Base class for IORails tool-calling rails.

Tool rails are local structural/schema validators. Unlike RailAction they make no LLM or API call, render no prompt, and need no model: they take already-normalized tool data (a Toolset, the model’s ToolCall list, or incoming ToolResult objects — all produced by the engine adapter) and return a RailResult. requires_model is therefore False and the only collaborator is an optional tracer for spans.

Subclasses set :attr:ToolRailAction.action_name and implement an async run with their own typed inputs (the inputs differ per rail), performing the check through :meth:ToolRailAction._guarded so every rail gets a consistent action span and turns an unexpected error into a blocking result rather than letting it propagate.

Module Contents

Classes

NameDescription
ToolRailActionBase for the local, model-free tool-calling rails (tool-call and tool-result).

Data

log

API

class nemoguardrails.guardrails.tool_rail_action.ToolRailAction(
tracer: typing.Optional['Tracer'] = None
)

Base for the local, model-free tool-calling rails (tool-call and tool-result).

action_name
str
requires_model
bool = False
nemoguardrails.guardrails.tool_rail_action.ToolRailAction._guarded(
check: typing.Callable[[], nemoguardrails.guardrails.guardrails_types.RailResult]
) -> nemoguardrails.guardrails.guardrails_types.RailResult

Run check inside an action span, converting any error into a block.

Mirrors RailAction’s error contract: an unexpected exception is recorded on the span and returned as RailResult(is_safe=False, ...) so a malformed input or a rail bug fails closed rather than crashing the request.

nemoguardrails.guardrails.tool_rail_action.log = logging.getLogger(__name__)