Skip to main content

ToolPolicy

Trait ToolPolicy 

Source
pub trait ToolPolicy:
    Send
    + Sync
    + 'static {
    // Required method
    fn authorize<'a>(
        &'a self,
        request: &'a PolicyRequest<'a>,
    ) -> Pin<Box<dyn Future<Output = PolicyDecision> + Send + 'a>>;

    // Provided method
    fn approved<'a>(
        &'a self,
        request: &'a PolicyRequest<'a>,
        approver: &'a str,
    ) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'a>> { ... }
}
Available on crate feature tool-loop only.
Expand description

Asked before every tool call runs, whatever kind it is (native, recovered from text, or repeated after a retry), and able to refuse it. Install with ToolLoop::with_policy.

An allowed task is not an authorised action: a task the caller may create does not authorise every tool a model may reach for. The policy decides per call, from the tool, the arguments and the request’s identity.

§Order

For a call authorize allows, nothing else is asked: it runs. For one it answers PolicyDecision::RequireApproval, the run is parked; once a person approves exactly that call, the loop asks authorize again (a Deny still denies), checks the decision against the call’s digest, and then, immediately before the call runs, tells the policy who approved it with approved. Only that hook sees the effective decision; a policy that must record or check an approved action does it there, and an Err stops the call (adversarial review N02, 2026-11-13).

Required Methods§

Source

fn authorize<'a>( &'a self, request: &'a PolicyRequest<'a>, ) -> Pin<Box<dyn Future<Output = PolicyDecision> + Send + 'a>>

Whether the call may run.

Provided Methods§

Source

fn approved<'a>( &'a self, request: &'a PolicyRequest<'a>, approver: &'a str, ) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'a>>

A call that authorize sent for approval has been approved by approver (the authenticated identity the approval gate verified) and is about to run. Err(reason) stops it: it is not run, and reason is its result as the model sees it.

The default lets it run.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§