Skip to navigation

nemoguardrails.server.hooks.adapters

View as MarkdownOpen in Claude

Each agent’s hook interface: the event its path handles, the tool call that event asks to check, and its answer.

Module Contents

Classes

NameDescription
HookAdapterOne agent’s path: the event it handles, the tool call that event’s body carries, and each outcome’s response.
UnsupportedHookEventErrorA hook_event_name that the agent’s path doesn’t handle.

Functions

NameDescription
_pre_tool_use_invocationThe tool call a Claude Code or Codex PreToolUse hook asks to check.
_pre_tool_use_outputClaude Code’s and Codex’s PreToolUse output: no decision for an allow, the deny shape for a deny.
_relay_decisionThe verdict the Relay plugin turns into its guardrail callback’s Ok(None) or Ok(Some(reason)).
_relay_invocationThe tool call a NeMo Relay guardrail asks to check, with no id: Relay passes its guardrail callback none.
_require_decisionRaise for an error outcome, which is answered with an error status, not a 200 body.

Data

ADAPTERS

DENY_REASON_PREFIX

HookAgent

API

class nemoguardrails.server.hooks.HookAdapter(
event: str,
request_model: type[pydantic.BaseModel],
invocation: typing.Callable[[Any], nemoguardrails.server.hooks.checking.ToolInvocation],
response_body: typing.Callable[[HookOutcome], dict]
)
Dataclass

One agent’s path: the event it handles, the tool call that event’s body carries, and each outcome’s response.

agent
HookAgent
event
str
invocation
Callable[[Any], ToolInvocation]
request_model
type[BaseModel]
response_body
Callable[[HookOutcome], dict]
nemoguardrails.server.hooks.HookAdapter.parse(
body: object

The tool call body asks to check, as this path’s event; error locations are relative to the body.

class nemoguardrails.server.hooks.UnsupportedHookEventError(
event: str,
handled_event: str
)
Exception

Bases: Exception

A hook_event_name that the agent’s path doesn’t handle.

The tool call a Claude Code or Codex PreToolUse hook asks to check.

nemoguardrails.server.hooks.adapters._pre_tool_use_output(
) -> dict

Claude Code’s and Codex’s PreToolUse output: no decision for an allow, the deny shape for a deny.

nemoguardrails.server.hooks.adapters._relay_decision(
) -> dict

The verdict the Relay plugin turns into its guardrail callback’s Ok(None) or Ok(Some(reason)).

The tool call a NeMo Relay guardrail asks to check, with no id: Relay passes its guardrail callback none.

nemoguardrails.server.hooks.adapters._require_decision(
) -> None

Raise for an error outcome, which is answered with an error status, not a 200 body.

nemoguardrails.server.hooks.adapters.ADAPTERS: dict[HookAgent, HookAdapter] = {(adapter.agent): adapter for adapter in (HookAdapter(agent='claude-code', event...
nemoguardrails.server.hooks.adapters.DENY_REASON_PREFIX = 'NeMo Guardrails: '
nemoguardrails.server.hooks.adapters.HookAgent = Literal['claude-code', 'codex', 'nemo-relay']