Skip to navigation

nemoguardrails.library.cel.actions

View as MarkdownOpen in Claude

Module Contents

Functions

NameDescription
_evaluateEvaluate all of a tool’s CEL expressions, blocking when any is true.
_programThe compiled program for expression, cached outside the config (see CelOptions.compile_expressions).
_tool_optionsReturn the tool’s CEL options for source.
evaluate_tool_call_celChecks a tool call’s arguments against that tool’s CEL expressions.
evaluate_tool_result_celChecks a tool result’s content against that tool’s CEL expressions.

Data

log

API

nemoguardrails.library.cel.actions._evaluate(
source: str,
tool_name: str,
variables: typing.Dict[str, typing.Any],

Evaluate all of a tool’s CEL expressions, blocking when any is true.

A failing expression (an error or a non-boolean result) raises even if another expression matched, so the rail fails closed.

nemoguardrails.library.cel.actions._program(
expression: str
) -> cel.Program

The compiled program for expression, cached outside the config (see CelOptions.compile_expressions).

nemoguardrails.library.cel.actions._tool_options(
config: nemoguardrails.RailsConfig,
source: str,
tool_name: str

Return the tool’s CEL options for source.

Raises when none are configured, so the rail fails closed: a tool the CEL rail runs for with no expressions to check cannot be validated.

nemoguardrails.library.cel.actions.evaluate_tool_call_cel(
source: str,
tool_definition: typing.Optional[nemoguardrails.guardrails.tool_schema.Tool],
config: nemoguardrails.RailsConfig,
kwargs = {}
async

Checks a tool call’s arguments against that tool’s CEL expressions.

Parameters:

source
str

Fixed per surface, always “tool_call”.

tool_call
ToolCall

ToolCall — The tool call to check. Its arguments are args and its name is tool.

tool_definition
Optional[Tool]

Optional[ Tool ] — The declared tool, used only by @tool_call_validation to check the call’s arguments against its schema before this function runs.

config
RailsConfig

RailsConfig — The rails configuration object.

Returns: RailOutcome

RailOutcome that blocks when any expression is true, with the matched expressions in

nemoguardrails.library.cel.actions.evaluate_tool_result_cel(
source: str,
config: nemoguardrails.RailsConfig,
kwargs = {}
async

Checks a tool result’s content against that tool’s CEL expressions.

Parameters:

source
str

Fixed per surface, always “tool_result”.

tool_call
ToolCall

ToolCall — The prior call this result answers. Its arguments are args and its name is tool.

tool_result
ToolResult

ToolResult — The tool result to check. Its content is result, as the tool returned it.

config
RailsConfig

RailsConfig — The rails configuration object.

Returns: RailOutcome

RailOutcome that blocks when any expression is true, with the matched expressions in

nemoguardrails.library.cel.actions.log = logging.getLogger(__name__)