Skip to navigation

Agent hook requests and responses for nemoguardrails hooks-server.

Submodules

Package Contents

Classes

NameDescription
HookAdapterOne agent’s path: the event it handles, the tool call that event’s body carries, and each outcome’s response.
HookErrorCodeThe error.code of a hooks request that ends in an error rather than an allow or a deny.
HookOutcomeA check’s verdict on a tool call, before it becomes the agent’s response.
UnsupportedHookEventErrorA hook_event_name that the agent’s path doesn’t handle.

Functions

NameDescription
check_messagesThe one assistant message carrying call, as check_async() takes it; with no id when the call has none.
check_toolsA compatibility declaration of the tool call names, as check_async() takes tools, for per-tool rails.
outcome_from_resultThe verdict a tool-call check’s result gives: allow, deny, or an error when no rail decided.

Data

ADAPTERS

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.HookErrorCode

Bases: enum.Enum

The error.code of a hooks request that ends in an error rather than an allow or a deny.

QUEUE_FULL
= 'queue_full'
RAIL_FAILED
= 'rail_failed'
UNSUPPORTED_HOOK_EVENT
= 'unsupported_hook_event'
class nemoguardrails.server.hooks.HookOutcome(
kind: typing.Literal['allow', 'deny', 'error'],
reason: typing.Optional[str] = None,
message: typing.Optional[str] = None
)
Dataclass

A check’s verdict on a tool call, before it becomes the agent’s response.

code
Optional[HookErrorCode] = None
kind
Literal['allow', 'deny', 'error']
message
Optional[str] = None
reason
Optional[str] = None
nemoguardrails.server.hooks.HookOutcome.__post_init__() -> None

Refuse any field the outcome’s kind doesn’t have, so only a valid allow, deny or error exists.

nemoguardrails.server.hooks.HookOutcome._require_text(
name: str
) -> None

Raise unless the field name holds a non-empty string.

nemoguardrails.server.hooks.HookOutcome._require_unset(
names: str = ()
) -> None

Raise when any of the fields names is set, since this kind of outcome has none of them.

nemoguardrails.server.hooks.HookOutcome.allow() -> nemoguardrails.server.hooks.checking.HookOutcome
classmethod
nemoguardrails.server.hooks.HookOutcome.deny(
reason: str
classmethod
nemoguardrails.server.hooks.HookOutcome.error(
message: str,
classmethod
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.

nemoguardrails.server.hooks.check_messages(
) -> list[dict]

The one assistant message carrying call, as check_async() takes it; with no id when the call has none.

nemoguardrails.server.hooks.check_tools(
) -> list[dict]

A compatibility declaration of the tool call names, as check_async() takes tools, for per-tool rails.

nemoguardrails.server.hooks.outcome_from_result(

The verdict a tool-call check’s result gives: allow, deny, or an error when no rail decided.

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