Skip to navigation

nemoguardrails.server.hooks.tool_policy

View as MarkdownOpen in Claude

The hooks server’s tool policy: which tools an agent’s call may use, and which of their arguments it may pass.

Module Contents

Classes

NameDescription
ToolPolicyhooks_server.allowed_tools, blocked_tools and allow_unlisted_tools, read once when the server starts.

Functions

NameDescription
_entriesEach tool a list names, with its entry’s arguments, or None for a bare name.

Data

ToolArguments

API

class nemoguardrails.server.hooks.tool_policy.ToolPolicy(
allowed: collections.abc.Mapping[str, nemoguardrails.server.hooks.tool_policy.ToolArguments] = (lambda: MappingProxyType({...,
blocked: collections.abc.Mapping[str, nemoguardrails.server.hooks.tool_policy.ToolArguments] = (lambda: MappingProxyType({...,
allow_unlisted: bool = True
)
Dataclass

hooks_server.allowed_tools, blocked_tools and allow_unlisted_tools, read once when the server starts.

allow_unlisted
bool = True
allowed
Mapping[str, ToolArguments]
blocked
Mapping[str, ToolArguments]
nemoguardrails.server.hooks.tool_policy.ToolPolicy.allowed_arguments(
name: str

The arguments name’s allowed_tools entry lists, or None when any argument is allowed.

nemoguardrails.server.hooks.tool_policy.ToolPolicy.blocked_by_name(
name: str
) -> bool

Whether blocked_tools names name bare, which blocks every call to it.

nemoguardrails.server.hooks.tool_policy.ToolPolicy.decide(
name: str,
arguments: collections.abc.Mapping[str, typing.Any]
) -> typing.Optional[str]

Why the policy denies a call to name with arguments, or None when it lets the call through.

nemoguardrails.server.hooks.tool_policy.ToolPolicy.denied_by_name(
name: str
) -> bool

Whether every call to name is denied: it’s blocked by name, or unlisted while unlisted tools are denied.

classmethod

The policy a config’s hooks_server section sets.

nemoguardrails.server.hooks.tool_policy._entries(
tool_list: collections.abc.Iterable[typing.Union[str, nemoguardrails.rails.llm.config.ToolEntry]]

Each tool a list names, with its entry’s arguments, or None for a bare name.

nemoguardrails.server.hooks.tool_policy.ToolArguments = Optional[tuple[str, ...]]