Skip to content

cayu.tools.policy

Public Cayu API. Definitions are grouped by their public source module, and definitions from private implementation modules appear on their package’s page; adding a symbol does not move existing links. The import shown at each entry is a supported public namespace. Read the Python API overview and install the required extra.

from cayu.tools import AllowAllToolPolicy

Bases: ToolPolicy.

AllowAllToolPolicy.execution_profile_identity() -> ExecutionProfileBehaviorIdentity | None

Return a stable application declaration, or None when non-portable.

async AllowAllToolPolicy.authorize(request: ToolPolicyRequest) -> ToolPolicyResult

Release source · Runtime guarantees · Capability guides

from cayu.tools import AllowlistRule

Allow a present argument only when it matches an allowed string.

A missing argument is intentionally allowed. Use RequiredAllowlistRule when omission must fail closed.

Bases: ParameterRule.

AllowlistRule.parameter() -> str
AllowlistRule.check(arguments: dict[str, Any]) -> str | None
AllowlistRule.violation_metadata(arguments: dict[str, Any]) -> dict[str, Any]

Return safe structured details for a rejected argument.

Custom rules remain source-compatible: rules that do not override this hook continue to emit the standard policy, tool, parameter, rule, and rule-index metadata.

AllowlistRule.is_validity_violation(arguments: dict[str, Any]) -> bool
AllowlistRule.__init__(parameter: str, *, values: Iterable[str]) -> None

Release source · Runtime guarantees · Capability guides

from cayu.tools import AlwaysRequireApprovalToolPolicy

Require caller approval for specific tools (or for every tool).

When tools is given, only those tool names require approval and the rest are allowed; when omitted, every tool call requires approval. Use this to gate side-effecting tools (post a PR comment, send an email) behind resolve_tool_approval without hand-writing a policy — instead of abusing a deny-everything rule. expires_in_seconds bounds how long the resulting pending approval stays resolvable before it deterministically denies.

Bases: ToolPolicy.

AlwaysRequireApprovalToolPolicy.execution_profile_identity() -> ExecutionProfileBehaviorIdentity | None

Return a stable application declaration, or None when non-portable.

async AlwaysRequireApprovalToolPolicy.authorize(request: ToolPolicyRequest) -> ToolPolicyResult
AlwaysRequireApprovalToolPolicy.__init__(*, tools: Iterable[str] | None=None, expires_in_seconds: float | None=None) -> None

Release source · Runtime guarantees · Capability guides

from cayu.tools import ANY_TAINT_LABEL
ANY_TAINT_LABEL = '*'

Release source · Runtime guarantees · Capability guides

from cayu.tools import DenyPatternRule

Reject a string argument when it matches one of the denied regex patterns.

Bases: ParameterRule.

DenyPatternRule.parameter() -> str
DenyPatternRule.check(arguments: dict[str, Any]) -> str | None
DenyPatternRule.violation_metadata(arguments: dict[str, Any]) -> dict[str, Any]

Return safe structured details for a rejected argument.

Custom rules remain source-compatible: rules that do not override this hook continue to emit the standard policy, tool, parameter, rule, and rule-index metadata.

DenyPatternRule.is_validity_violation(arguments: dict[str, Any]) -> bool
DenyPatternRule.__init__(parameter: str, *, patterns: Iterable[str]) -> None

Release source · Runtime guarantees · Capability guides

from cayu.tools import EnvironmentScopedToolPolicy

Pre-authorize explicit tools in named execution environments.

allow maps tool names to exact environment names (no wildcards). Unlisted tools, empty scopes, and missing or unmatched environments deny. Only trusted request context is checked, never model-provided arguments. Names are public application identifiers, not credentials. Authorization does not establish containment or bypass environment execution admission.

Bases: ToolPolicy.

EnvironmentScopedToolPolicy.execution_profile_identity() -> ExecutionProfileBehaviorIdentity | None

Return a stable application declaration, or None when non-portable.

async EnvironmentScopedToolPolicy.authorize(request: ToolPolicyRequest) -> ToolPolicyResult
EnvironmentScopedToolPolicy.__init__(*, allow: Mapping[str, Iterable[str]]) -> None
EnvironmentScopedToolPolicy.allow() -> Mapping[str, frozenset[str]]

Release source · Runtime guarantees · Capability guides

from cayu.tools import EveryCallRule

Match every call so the policy’s decision applies to the whole tool.

With ParameterConstrainedToolPolicy(..., decision=REQUIRE_APPROVAL) each call to the tool pauses for human approval; with DENY it is blocked. Use it for tools whose every invocation is consequential, such as sending a message or writing an external record.

Bases: ParameterRule.

EveryCallRule.parameter() -> str
EveryCallRule.check(arguments: dict[str, Any]) -> str | None
EveryCallRule.violation_metadata(arguments: dict[str, Any]) -> dict[str, Any]

Return safe structured details for a rejected argument.

Custom rules remain source-compatible: rules that do not override this hook continue to emit the standard policy, tool, parameter, rule, and rule-index metadata.

EveryCallRule.is_validity_violation(arguments: dict[str, Any]) -> bool

Whether approval cannot repair this violation; custom rules default to authority.

Release source · Runtime guarantees · Capability guides

from cayu.tools import GuardedToolPolicy

Apply deny-or-continue guards, then one enforcing downstream policy.

A guard cannot authorize a call. Invalid returns and ordinary exceptions deny with fixed content-free text; cancellation still propagates.

Bases: ToolPolicy.

GuardedToolPolicy.execution_profile_identity() -> ExecutionProfileBehaviorIdentity | None

Return a stable application declaration, or None when non-portable.

async GuardedToolPolicy.authorize(request: ToolPolicyRequest) -> ToolPolicyResult
GuardedToolPolicy.__init__(*, guards: Iterable[ToolPolicyGuard], then: ToolPolicy) -> None
GuardedToolPolicy.guards() -> tuple[ToolPolicyGuard, ...]
GuardedToolPolicy.then() -> ToolPolicy

Release source · Runtime guarantees · Capability guides

from cayu.tools import metadata_with_taint_labels
metadata_with_taint_labels(metadata: Mapping[str, Any], labels: Iterable[str]) -> dict[str, Any]

Release source · Runtime guarantees · Capability guides

from cayu.tools import ParameterConstrainedToolPolicy

Validate tool-call arguments with per-tool parameter rules.

Tools not present in rules are allowed. For constrained tools, the first validity violation always denies: approval cannot repair missing, empty or wrongly typed arguments. Authority violations return decision with a structured metadata payload. Validity checks take precedence over authority violations, even when an authority rule appears first.

Bases: ToolPolicy.

ParameterConstrainedToolPolicy.execution_profile_identity() -> ExecutionProfileBehaviorIdentity | None
async ParameterConstrainedToolPolicy.authorize(request: ToolPolicyRequest) -> ToolPolicyResult
ParameterConstrainedToolPolicy.__init__(rules: dict[str, Iterable[ParameterRule]], *, decision: ToolPolicyDecision=ToolPolicyDecision.DENY, execution_profile_identity: ExecutionProfileBehaviorIdentity | None=None) -> None

Release source · Runtime guarantees · Capability guides

from cayu.tools import ParameterRule

Validates one argument path in a tool call.

A path can be a top-level argument name such as "to" or a dotted path such as "request.url" for nested JSON objects.

Bases: ABC.

ParameterRule.parameter() -> str

Human-readable argument path this rule validates.

ParameterRule.check(arguments: dict[str, Any]) -> str | None

Return a violation reason, or None when the arguments satisfy the rule.

ParameterRule.violation_metadata(arguments: dict[str, Any]) -> dict[str, Any]

Return safe structured details for a rejected argument.

Custom rules remain source-compatible: rules that do not override this hook continue to emit the standard policy, tool, parameter, rule, and rule-index metadata.

ParameterRule.is_validity_violation(arguments: dict[str, Any]) -> bool

Whether approval cannot repair this violation; custom rules default to authority.

Release source · Runtime guarantees · Capability guides

from cayu.tools import RequiredAllowlistRule

Require a non-empty string argument that matches an explicit allowlist.

Bases: ParameterRule.

RequiredAllowlistRule.parameter() -> str
RequiredAllowlistRule.check(arguments: dict[str, Any]) -> str | None
RequiredAllowlistRule.violation_metadata(arguments: dict[str, Any]) -> dict[str, Any]
RequiredAllowlistRule.is_validity_violation(arguments: dict[str, Any]) -> bool
RequiredAllowlistRule.__init__(parameter: str, *, values: Iterable[str]) -> None

Release source · Runtime guarantees · Capability guides

from cayu.tools import RequiredArguments

Deny missing or empty argument paths before the downstream policy runs.

RequiredArguments.__init__(rules: Mapping[str, Iterable[str]]) -> None
async RequiredArguments.check(request: ToolPolicyRequest) -> ToolPolicyResult | None

Release source · Runtime guarantees · Capability guides

from cayu.tools import RequiredFieldRule

Require an argument path to be present and non-empty.

Bases: ParameterRule.

RequiredFieldRule.parameter() -> str
RequiredFieldRule.check(arguments: dict[str, Any]) -> str | None
RequiredFieldRule.violation_metadata(arguments: dict[str, Any]) -> dict[str, Any]

Return safe structured details for a rejected argument.

Custom rules remain source-compatible: rules that do not override this hook continue to emit the standard policy, tool, parameter, rule, and rule-index metadata.

RequiredFieldRule.is_validity_violation(arguments: dict[str, Any]) -> bool
RequiredFieldRule.__init__(parameter: str) -> None

Release source · Runtime guarantees · Capability guides

from cayu.tools import StaticToolPolicy

Simple allow/deny policy for static tool scopes.

Deny rules win over allow rules. When allow is omitted, all tools are allowed except explicitly denied tools. When allow is provided, only those tools are allowed.

Bases: ToolPolicy.

StaticToolPolicy.execution_profile_identity() -> ExecutionProfileBehaviorIdentity | None

Return a stable application declaration, or None when non-portable.

async StaticToolPolicy.authorize(request: ToolPolicyRequest) -> ToolPolicyResult
StaticToolPolicy.__init__(*, allow: Iterable[str] | None=None, deny: Iterable[str] | None=None) -> None

Release source · Runtime guarantees · Capability guides

from cayu.tools import taint_labels_from_metadata
taint_labels_from_metadata(metadata: Mapping[str, Any]) -> frozenset[str]

Release source · Runtime guarantees · Capability guides

from cayu.tools import TAINT_LABELS_METADATA_KEY
TAINT_LABELS_METADATA_KEY = 'cayu:taint_labels'

Release source · Runtime guarantees · Capability guides

from cayu.tools import TaintAwareToolPolicy

Protect sensitive tools after untrusted tool output enters a session.

This policy does not scan content for prompt-injection strings. Instead, apps classify tool boundaries:

  • taint_sources maps inbound/untrusted tool names to taint labels.
  • protected_tools maps sensitive outbound tools to labels that should deny or require approval once present in the session.

Cayu’s runtime supplies durable prior labels through request.metadata["cayu:taint_labels"] and adds same-round labels while planning a batch of tool calls.

Bases: ToolPolicy.

TaintAwareToolPolicy.execution_profile_identity() -> ExecutionProfileBehaviorIdentity | None

Return a stable application declaration, or None when non-portable.

async TaintAwareToolPolicy.authorize(request: ToolPolicyRequest) -> ToolPolicyResult
TaintAwareToolPolicy.__init__(*, taint_sources: Mapping[str, Iterable[str]], protected_tools: Mapping[str, Iterable[str]], decision: ToolPolicyDecision=ToolPolicyDecision.REQUIRE_APPROVAL) -> None
TaintAwareToolPolicy.labels_for_source_tool(tool_name: str) -> frozenset[str]

Return labels added when tool_name produces a terminal result.

TaintAwareToolPolicy.protected_labels_for_tool(tool_name: str) -> frozenset[str]

Return taint labels that protect tool_name.

Release source · Runtime guarantees · Capability guides

from cayu.tools import TOOL_POLICY_REAUTHORIZATION_METADATA_KEY
TOOL_POLICY_REAUTHORIZATION_METADATA_KEY = 'cayu:tool_policy_reauthorization'

Release source · Runtime guarantees · Capability guides

from cayu.tools import ToolPolicy

Authorizes registered tool calls before execution.

Bases: ABC.

ToolPolicy.execution_profile_identity() -> ExecutionProfileBehaviorIdentity | None

Return a stable application declaration, or None when non-portable.

async ToolPolicy.authorize(request: ToolPolicyRequest) -> ToolPolicyResult

Return whether this tool call may execute.

Release source · Runtime guarantees · Capability guides

from cayu.tools import ToolPolicyDecision

Bases: StrEnum.

Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.

Name Type Default
ALLOW class attribute 'allow'
DENY class attribute 'deny'
REQUIRE_APPROVAL class attribute 'require_approval'

Release source · Runtime guarantees · Capability guides

from cayu.tools import ToolPolicyGuard

A narrowing guard: return None to continue or a DENY result.

Custom guards can declare execution_profile_identity for portable recovery. An undeclared guard keeps the composite process-local.

Bases: Protocol.

async ToolPolicyGuard.check(request: ToolPolicyRequest) -> ToolPolicyResult | None

Release source · Runtime guarantees · Capability guides

from cayu.tools import ToolPolicyRequest

Input passed to a tool policy before a registered tool executes.

Bases: BaseModel.

Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.

Name Type Default
session Session required
agent AgentSpec required
tool_name str required
tool_call_id str required
tool_effect ToolEffect ToolEffect.EXTERNAL
arguments dict[str, Any] Field(default_factory=dict)
environment_name str | None None
workspace_id str | None None
metadata dict[str, Any] Field(default_factory=dict)
ToolPolicyRequest.validate_nonblank_fields(value: str, info) -> str
ToolPolicyRequest.validate_optional_names(value: str | None, info) -> str | None
ToolPolicyRequest.copy_json_fields(value: dict[str, Any], info) -> dict[str, Any]

Release source · Runtime guarantees · Capability guides

from cayu.tools import ToolPolicyResult

Authorization decision for one tool call.

approval_expires_in_seconds is honored only when decision is REQUIRE_APPROVAL: the runtime converts it to an absolute expires_at on the pending approval checkpoint, after which resolution deterministically denies the round. None means the approval never expires.

Bases: BaseModel.

Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.

Name Type Default
decision ToolPolicyDecision required
reason str | None None
metadata dict[str, Any] Field(default_factory=dict)
command_denial_code CommandDenialCode | None Field(default=None, exclude_if=lambda value: value is None)
approval_expires_in_seconds float | None None
ToolPolicyResult.validate_optional_reason(value: str | None, info) -> str | None
ToolPolicyResult.copy_metadata(value: dict[str, Any]) -> dict[str, Any]

validate_approval_expires_in_seconds (method)

Section titled “validate_approval_expires_in_seconds (method)”
ToolPolicyResult.validate_approval_expires_in_seconds(value: object) -> float | None

Release source · Runtime guarantees · Capability guides