ToolApprovalPolicy

Which tool calls need a human yes before they run.

Some tools shouldn't fire on the model's say-so alone. Anything that spends money, sends a message, or deletes something. A policy sits between the model asking and the tool running, and pauses the loop until you approve.

You can require approval for everything, for nothing, or for a named set. The loop surfaces the pending call, waits, and resumes with your answer.

let result = try await generateText(
  model: AnthropicModel("claude-sonnet-5"),
  prompt: prompt,
  tools: [search, sendEmail],
  toolApproval: .requiring(["send_email"])
)

Declaration

public struct ToolApprovalPolicy

Defined in Sources/AI/Core/ToolApproval.swift.

Initializers

init(
    _ decide: @escaping @Sendable (ToolApprovalContext) async -> ToolApprovalDecision
)
init(
    dictionaryLiteral elements: (String, ToolApprovalDecision)...
)
init(
    _ decisions: [String: ToolApprovalDecision]
)

Methods

func decide(
    _ context: ToolApprovalContext
) async -> ToolApprovalDecision

See also