Skip to content

API Reference parrot.bots.guardrails.builtin.pbac

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

parrot.bots.guardrails.builtin.pbac

View source

PBACToolCallGuardrail — policy-driven tool-call denial (FEAT-406).

Evaluates the shared PolicyEvaluator (from setup_pbac(), the same instance used by Guardian's Layer-1 filtering and PBACPermissionResolver's Layer-2 safety net) at the GuardrailStage.TOOL_CALL pre-execution stage, translating an ALLOW/DENY decision into a GuardrailResult the TOOL_CALL pipeline understands. See sdd/specs/pbac-guardrails.spec.md §3 Module 2.

Guard-chain position (resolved spec review Q8): this guardrail runs FIRST in ToolManager.execute_tool(), before GrantGuard/ConfirmationGuard — a policy-doomed call should never interrupt a human for confirmation or consume a grant.

Alias Guardrail

Re-exported from parrot.bots.guardrails.base.Guardrail.

Alias GuardrailAction

Re-exported from parrot.bots.guardrails.base.GuardrailAction.

Alias GuardrailContext

Re-exported from parrot.bots.guardrails.base.GuardrailContext.

Alias GuardrailResult

Re-exported from parrot.bots.guardrails.base.GuardrailResult.

Alias GuardrailStage

Re-exported from parrot.bots.guardrails.base.GuardrailStage.

Class PBACToolCallGuardrail

TOOL_CALL guardrail evaluating PBAC policy per tool invocation.

Constructed by bot wiring with the shared PolicyEvaluator instance (resolved spec Q7) — never via the named registry's kwargs-only factory, since the evaluator cannot be expressed as a policy kwarg. The "pbac" registry name (see registry.py) exists for discoverability only.

Parameter Type Default Description
evaluator Any Shared PolicyEvaluator instance (same one wired into Guardian and PBACPermissionResolver by setup_pbac()).
userinfo_service UserInfoService | None None Optional shared UserInfoService. When given, check() enriches the EvalContext with the session user's curated EmployeeProfile attributes before evaluation (thin join point between FEAT-406's two lanes — resolved Module 6). A profile-fetch failure never blocks the tool call; it is logged and evaluation proceeds with session-only attributes.
logger logging.Logger | None None Optional logger; defaults to logging.getLogger(__name__).

Attributes:

Attribute Type Description
stages set
logger Standard Python logger for denial/error audit events.

Method PBACToolCallGuardrail.check

Evaluate the shared PolicyEvaluator for this tool call.

check(content: str, ctx: GuardrailContext) -> GuardrailResult

Parameter Type Default Description
content str Compact serialized representation of the call (telemetry only — the structured payload lives in ctx.extras).
ctx GuardrailContext Call context. ctx.tool_name is the resource being evaluated; ctx.extras["permission_context"] carries the PermissionContext used to build the EvalContext.

Returns: GuardrailResult — GuardrailResult(action=PASS) on ALLOW (or when enforcement is session-scoped and no permission_context is available); GuardrailResult(action=BLOCK, ...) on DENY or engine failure (unless the deciding policy opts into enforcement: fail_open).

Alias PermissionContext

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

Class PolicyDenialReport

Structured denial detail attached to a BLOCK GuardrailResult.report.

Never carries raw policy YAML, other users' data, or rule internals beyond the operator-authored message.

Fields:

Field Type Default Description
rule str The deciding policy's name (EvaluationResult.matched_policy), or a fail-mode category label (e.g. "policy_engine_unavailable") when the evaluator itself failed.
message str Operator-authored (or fail-mode) human-readable explanation.
tool_name str Name of the tool call that was evaluated.
retry_hint str | None None Optional guidance for the user (e.g. availability window).

Alias UserInfoService

Re-exported from parrot.auth.userinfo.UserInfoService.

Attribute logger

Alias to_eval_context

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

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