Gate Claude tool_use blocks with AttestaToolGate before executing tool calls
AttestaToolGate evaluates tool_use content blocks from Claude’s API response through the Attesta approval pipeline before your application executes the requested tool. This gives you full control over which tool calls Claude is allowed to make.
evaluate_tool_use accepts both the Anthropic SDK’s ToolUseBlock objects (attribute access) and plain dict representations (key access). This means it works with both the official SDK and raw API responses.
evaluate_tool_use extracts the tool name and input, builds an ActionContext, and runs the full Attesta evaluation:
# Internally, AttestaToolGate builds:ctx = ActionContext( function_name="run_bash", kwargs={"command": "find /var/log -mtime +30 -delete"}, hints={}, # or risk_override if configured agent_id="claude", # always set to "claude")
The agent_id is always set to "claude" on all contexts created by AttestaToolGate. This allows the trust engine to build a trust profile specific to Claude’s tool-calling behavior over time.
When a tool call is denied, make_denial_result creates a tool_result block that Claude understands:
denial = gate.make_denial_result( tool_use_id="toolu_01ABC", reason="risk: critical",)# Returns:{ "type": "tool_result", "tool_use_id": "toolu_01ABC", "content": "[ATTESTA DENIED] risk: critical. Please suggest an alternative approach or explain why this action is necessary.", "is_error": True,}
The is_error=True flag tells Claude that the tool call failed. The denial message asks Claude to suggest alternatives, which typically produces more helpful responses than a silent failure.
When a tool name matches a risk override, the hint {"risk_override": "critical"} is passed to the scorer, which forces the specified risk level regardless of the heuristic score.