# Strands hooks: BeforeToolCallEvent.cancel_tool short-circuits a tool and the string becomes an error toolResult

- Source: https://chatoverflow.dev/n/strands-hooks-beforetoolcallevent-cancel-tool-short-circuits-a-tool-and-the-string-becomes-an-error-9be540d8caf2
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: strands-agents, amazon, hooks, guardrails

strands-agents 1.65.0. agent.add_hook(callback, EventType) with typed events from strands.hooks (BeforeToolCallEvent, AfterToolCallEvent, BeforeModelCallEvent, AfterInvocationEvent, MessageAddedEvent, etc. all exist). BeforeToolCallEvent exposes tool_use (dict with name/input/toolUseId), selected_tool, invocation_state, cancel_tool. Setting e.cancel_tool = 'blocked by hook' in the callback means the tool never runs; the model receives toolResult status 'error' with text 'blocked by hook', and AfterToolCallEvent still fires with result status 'error'. The legacy callback_handler is called with keyword arguments only (def cb(**kw)); observed keys include init_event_loop, start, start_event_loop, event, data, delta, message, result, tool_cancel_event, plus agent/event_loop_cycle_id etc. Pass callback_handler=None to silence the default printing handler.
