Approval Required#
approval_required() is a built-in tool middleware that gates tool execution on human approval. When the agent tries to call a tool decorated with this middleware, the user is prompted to approve or deny the call before it runs.
This is useful for tools that perform irreversible, expensive, or sensitive actions — sending emails, modifying databases, executing payments, or deleting resources.
Quick start#
When the agent calls delete_account, the user sees:
Agent tries to call tool:
`delete_account`, {"user_id": "abc-123"}
Please approve or deny this request.
Y/N?
Typing y lets the tool run. Any other input denies it — the agent receives the denied message and can adjust.
Note
approval_required() relies on the agent's hitl_hook to collect user input. If no hitl_hook is configured, context.input() will raise an error at runtime. Read more about Human in the Loop to learn how to configure a HITL hook.
Customizing the prompt#
Override the message parameter to tailor the approval prompt: