inspect_ai.approval

Approvers and approval policies.

Approvers

auto_approver

Automatically apply a decision to tool calls.

@approver(name="auto")
def auto_approver(decision: ApprovalDecision = "approve") -> Approver
decision ApprovalDecision

Decision to apply.

human_approver

Interactive human approver.

@approver(name="human")
def human_approver(
    choices: list[ApprovalDecision] = ["approve", "reject", "terminate"],
) -> Approver
choices list[ApprovalDecision]

Choices to present to human.

read_approval_policies

Read approval policies from a JSON or YAML config file.

def read_approval_policies(file: str) -> list[ApprovalPolicy]
file str

JSON or YAML config file with approval policies.

approval

Context manager to temporarily replace tool approval policies.

@contextlib.contextmanager
def approval(
    policies: list[ApprovalPolicy],
) -> Iterator[None]
policies list[ApprovalPolicy]

Approval policies to use within the context.

Types

Approver

Approve or reject a tool call.

class Approver(Protocol):
    async def __call__(
        self,
        message: str,
        call: ToolCall,
        view: ToolCallView,
        history: list[ChatMessage],
    ) -> Approval
message str

Message genreated by the model along with the tool call.

call ToolCall

The tool call to be approved.

view ToolCallView

Custom rendering of tool context and call.

history list[ChatMessage]

The current conversation history.

Approval

Approval details (decision, explanation, etc.)

class Approval(BaseModel)

Attributes

decision ApprovalDecision

Approval decision.

modified ToolCall | None

Modified tool call for decision ‘modify’.

explanation str | None

Explanation for decision.

metadata dict[str, Any] | None

Additional approval metadata.

ApprovalDecision

Represents the possible decisions in an approval.

ApprovalDecision = Literal["approve", "modify", "reject", "terminate", "escalate"]

ApprovalPolicy

Policy mapping approvers to tools.

@dataclass
class ApprovalPolicy

Attributes

approver Approver

Approver for policy.

tools str | list[str]

Tools to use this approver for (can be full tool names or globs).

Decorator

approver

Decorator for registering approvers.

def approver(*args: Any, name: str | None = None, **attribs: Any) -> Any
*args Any

Function returning Approver targeted by plain approver decorator without attributes (e.g. @approver)

name str | None

Optional name for approver. If the decorator has no name argument then the name of the function will be used to automatically assign a name.

**attribs Any

Additional approver attributes.