[fix] Added can_use_tool callback and prompt change to prevent AskUserQuestion error#294
Merged
calreynolds merged 1 commit intodatabricks-solutions:mainfrom Mar 11, 2026
Conversation
calreynolds
approved these changes
Mar 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AskUserQuestion Tool Failures in Downstream UIs
Problem
When Claude calls the
AskUserQuestiontool during a builder-app agent session, it producesis_error=Truetool results. In downstream applications that proxy builder-app events, this renders as a red "Failed" status in the UI. The agent may also stop entirely instead of asking questions as normal text.Root Cause
The builder-app runs
claude-agent-sdkwithpermission_mode='bypassPermissions'and nocan_use_toolcallback (agent.py:454).bypassPermissionsauto-allows regular tools (Bash, Write, etc.) at the CLI level without ever sending a control request to the SDK. However,AskUserQuestionis different — it requires structured user answers (questions+answerspayload), so the CLI still sends acan_use_toolcontrol request to the SDK.With no callback registered, the SDK raises:
Source:
claude_agent_sdk/_internal/query.py:241-242This error is returned to the CLI as a control protocol error response, which the CLI converts into a
ToolResultBlockwithis_error=True.Resolution
Two-layer fix applied:
1. System prompt instruction (primary)
Tells Claude not to use
AskUserQuestionand to ask questions directly in text responses instead. This prevents the tool from being called in the first place.File:
server/services/system_prompt.py2.
can_use_toolcallback (safety net)Intercepts
AskUserQuestionwithPermissionResultAllowand synthetic answers that redirect Claude to ask questions in text. Returns a successful result — nois_error, no red "Failed" in downstream UIs. All other tools pass through as auto-allowed.Requires a
PreToolUsekeepalive hook per the Python SDK requirement. No websocket, no timeout concerns, no architectural changes — the callback returns immediately with a static response.File:
server/services/agent.pyFiles Changed
server/services/system_prompt.pyserver/services/agent.pycan_use_toolcallback,_keepalive_hook,PermissionResult*/ToolPermissionContextimportsDocumentation