Skip to content

API Reference parrot.auth.confirmation

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.auth.confirmation

View source

Confirmation subsystem for per-call HITL tool-call review (FEAT-235).

Alias AbstractTool

Re-exported from parrot.tools.abstract.AbstractTool.

Alias AbstractToolArgsSchema

Re-exported from parrot.tools.abstract.AbstractToolArgsSchema.

Class ConfirmationConfig

Configurable defaults for the confirmation subsystem.

Mirrors :class:GrantConfig (grants.py:95).

Fields:

Field Type Default Description
window_seconds int Default approval window in seconds. 0 (default) means "always re-ask" — the safe, per-call default.
approval_timeout float Seconds to wait for a human response before timing out and failing closed (default 120 s).
default_channel str 'telegram' HITL channel to use when the permission context does not specify one (default "telegram").
max_edit_retries int Maximum number of times the guard re-asks after invalid edited values before auto-cancelling (default 1).

Class ConfirmationDecision

Result of ConfirmationGuard.confirm().

Mirrors :class:GuardDecision (grants.py:320).

Fields:

Field Type Default Description
allowed bool Whether the tool call is permitted to proceed.
status Literal['confirmed', 'cancelled', 'timeout', 'not_required'] 'confirmed' Outcome token — one of confirmed, cancelled, timeout, not_required.
reason str Human-readable explanation of the decision.
parameters Optional[Dict[str, Any]] None (Possibly edited and re-validated) parameters to pass to tool.execute(). None means use the original parameters.

Class ConfirmationGuard

The Governor: asks a human to confirm each marked tool call.

Mirrors :class:GrantGuard (grants.py:338) in structure. Wired into ToolManager via set_confirmation_guard() and invoked in execute_tool() after the grant check and before tool.execute().

Parameter Type Default Description
store ConfirmationWindowStore Window store to consult and write confirmed calls.
human_manager Optional['HumanInteractionManager'] None Optional HITL manager. None → fail-closed mode.
config Optional[ConfirmationConfig] None Optional configuration overrides (uses defaults if None).

Method ConfirmationGuard.confirm

Decide whether this specific tool call may proceed.

confirm(*, tool: 'AbstractTool', parameters: dict, permission_context: Optional['PermissionContext'] = None) -> ConfirmationDecision

Parameter Type Default Description
tool 'AbstractTool' The tool being called. Must have a routing_meta dict.
parameters dict The parameters for this call.
permission_context Optional['PermissionContext'] None Caller's permission context. Provides user_id for window keying. Uses "anonymous" if None.

Returns: ConfirmationDecision — class:ConfirmationDecision indicating whether the call is allowed.

Class ConfirmationWindowStore

Abstract window persistence for the confirmation subsystem.

Mirrors :class:GrantStore (grants.py:114).

Key = (owner_id, tool_name, args_hash). Implementations must be thread-safe and support concurrent async access.

Method ConfirmationWindowStore.is_confirmed

Return True if a non-expired confirmation window covers this call.

is_confirmed(owner_id: str, tool_name: str, args_hash: str) -> bool

Parameter Type Default Description
owner_id str The actor who confirmed the tool call.
tool_name str Name of the tool.
args_hash str Stable hash of the call parameters.

Returns: bool — True if a live window exists; False otherwise.

Method ConfirmationWindowStore.record

Record a confirmed call in the window store.

When window_seconds == 0 the implementation MUST store nothing so that subsequent is_confirmed calls always return False (always re-ask behaviour).

record(owner_id: str, tool_name: str, args_hash: str, *, window_seconds: int) -> None

Parameter Type Default Description
owner_id str The actor who confirmed the tool call.
tool_name str Name of the tool.
args_hash str Stable hash of the call parameters.
window_seconds int Duration of the window in seconds. 0 means do not store.

Alias HumanInteractionManager

Re-exported from parrot.human.manager.HumanInteractionManager.

Class InMemoryConfirmationWindowStore

asyncio.Lock-guarded dict-backed window store with TTL expiry.

All mutations are protected by an :class:asyncio.Lock to prevent TOCTOU races under concurrent tool calls. Mirrors :class:InMemoryGrantStore (grants.py:185).

Method InMemoryConfirmationWindowStore.is_confirmed

Return True only if a non-expired window exists for this call.

is_confirmed(owner_id: str, tool_name: str, args_hash: str) -> bool

Parameter Type Default Description
owner_id str The actor who confirmed the tool call.
tool_name str Name of the tool.
args_hash str Stable hash of the call parameters.

Returns: bool — True if an active (non-expired) window covers the key.

Method InMemoryConfirmationWindowStore.record

Record a confirmed call; noop when window_seconds == 0.

record(owner_id: str, tool_name: str, args_hash: str, *, window_seconds: int) -> None

Parameter Type Default Description
owner_id str The actor who confirmed the tool call.
tool_name str Name of the tool.
args_hash str Stable hash of the call parameters.
window_seconds int Window duration. 0 means do not store.

Alias PermissionContext

Re-exported from parrot.auth.permission.PermissionContext.

Alias WaitStrategy

Re-exported from parrot.human.models.WaitStrategy.

Function build_form_schema

Build a FORM interaction schema from the tool's args_schema.

Derives a form_schema dict for a HumanInteraction(type=FORM) interaction, pre-filled with the current parameters so the human sees the intended values and can edit them.

The produced schema passes the HumanInteraction model_validator (non-empty dict requirement).

build_form_schema(tool: 'AbstractTool', parameters: dict) -> dict

Parameter Type Default Description
tool 'AbstractTool' The tool being confirmed.
parameters dict Current call parameters (used as default values).

Returns: dict — A non-empty form_schema dict suitable for HumanInteraction.form_schema.

Function compute_args_hash

Produce a stable SHA-256 hash over normalized parameters.

The hash is deterministic across runs: keys are sorted and values are serialized with json.dumps(..., sort_keys=True, default=str) to handle non-JSON-serialisable values gracefully.

compute_args_hash(parameters: dict) -> str

Parameter Type Default Description
parameters dict Tool call parameters to hash.

Returns: str — Hex-encoded SHA-256 digest of the canonical parameter serialization.

Alias consume_confirmed_call

Re-exported from parrot.auth.approval_token.consume_confirmed_call.

Alias current_confirmed_call

Re-exported from parrot.auth.approval_token.current_confirmed_call.

Alias is_enforced_write_class

Re-exported from parrot.auth.approval_token.is_enforced_write_class.

Function render_briefing

Render a confirmation briefing string for the tool call.

Tries to format tool.routing_meta.get("confirm_template") against a context dict {tool, params, **parameters} using safe string formatting. Falls back to a raw "<tool.name> with: k=v, …" listing on any template error (missing key, bad format, etc.).

Never uses eval or format_map with untrusted attribute access.

render_briefing(tool: 'AbstractTool', parameters: dict) -> str

Parameter Type Default Description
tool 'AbstractTool' The tool being confirmed.
parameters dict The call parameters.

Returns: str — A human-readable briefing string.

Function revalidate_edit

Validate edited values against the tool's args_schema.

revalidate_edit(tool: 'AbstractTool', edited: dict) -> dict

Parameter Type Default Description
tool 'AbstractTool' The tool being confirmed (provides args_schema).
edited dict The edited parameter dict returned by the human.

Returns: dict — Validated (and possibly coerced) parameter dict.

Raises:

  • ValidationError — If the edited values do not pass schema validation.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally