{"record":{"id":"caa8503557ffcc10","repo":"langchain-ai/deepagents","slug":"user-prompt-submission-stopped-by-hook","errorCode":null,"errorMessage":"User prompt submission stopped by hook","messagePattern":"User prompt submission stopped by hook","errorType":"exception","errorClass":"ClientHookStopError","httpStatus":null,"severity":"warning","filePath":"libs/code/deepagents_code/tui/textual_adapter.py","lineNumber":1829,"sourceCode":"            user_msg.update(message_kwargs)\n        additional_kwargs = user_msg.get(\"additional_kwargs\")\n        trusted_kwargs = (\n            dict(additional_kwargs) if isinstance(additional_kwargs, dict) else {}\n        )\n        trusted_kwargs[USER_PROMPT_METADATA_KEY] = user_prompt_metadata(\n            user_input,\n            [str(path) for path in mentioned_files],\n            turn_id=turn_id,\n        )\n        user_msg[\"additional_kwargs\"] = trusted_kwargs\n        messages: list[dict[str, Any]] = []\n        transcript.append([HumanMessage(content=message_content or \"\")])\n        if hooks.has_handlers(HookEvent.USER_PROMPT_SUBMIT):\n            prompt_outcome = await hooks.on_user_prompt(user_input)\n            if not prompt_outcome.ok:\n                from deepagents_code.hooks.client_lifecycle import ClientHookStopError\n\n                raise ClientHookStopError(\n                    prompt_outcome.stop_reason\n                    or \"User prompt submission stopped by hook\"\n                )\n        else:\n            prompt_outcome = PromptOutcome()\n            await dispatch_hook(\"session.start\", {\"thread_id\": thread_id})\n            await dispatch_hook(\"user.prompt\", {})\n        session_context = hooks.take_pending_context(thread_id=thread_id)\n        if session_context:\n            messages.append({\"role\": \"system\", \"content\": \"\\n\\n\".join(session_context)})\n        if prompt_outcome.context:\n            messages.append(\n                {\"role\": \"system\", \"content\": \"\\n\\n\".join(prompt_outcome.context)}\n            )\n        if not prompt_outcome.suppress_original_prompt:\n            messages.append(user_msg)\n        stream_input: dict | Command = {\n            \"messages\": messages,","sourceCodeStart":1811,"sourceCodeEnd":1847,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/tui/textual_adapter.py#L1811-L1847","documentation":"When a UserPromptSubmit hook is registered, execute_task_textual awaits hooks.on_user_prompt before running the agent; if the hook returns an unsuccessful outcome, a ClientHookStopError is raised using the hook's stop_reason (defaulting to this message). This lets user hooks veto prompts before any model call.","triggerScenarios":"A configured user_prompt_submit hook returns ok=false for the submitted prompt; the submission then aborts with ClientHookStopError carrying the hook's stop_reason.","commonSituations":"Project hook scripts that block prompts matching policy rules (e.g. secrets, forbidden commands); hooks that fail validation and intentionally stop the turn; misconfigured hooks returning a failed status on valid input.","solutions":["Read prompt_outcome.stop_reason / the raised message to see why the hook rejected the prompt and adjust the input accordingly.","Fix or relax the hook script so legitimate prompts pass.","Temporarily disable the USER_PROMPT_SUBMIT hook in settings if it is misbehaving.","Handle ClientHookStopError in the caller to show the stop reason instead of a generic failure."],"exampleFix":"// before\nawait execute_task_textual(adapter, user_input)  # raises ClientHookStopError\n// after\ntry:\n    await execute_task_textual(adapter, user_input)\nexcept ClientHookStopError as exc:\n    adapter._update_status(f\"Prompt blocked by hook: {exc}\")","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    await execute_task_textual(adapter, user_input)\nexcept ClientHookStopError as exc:\n    show_status(f\"Prompt blocked by hook: {exc}\")","preventionTips":["Test project hooks against representative prompts before enabling them for the team.","Log hook stop_reason values to make vetoes diagnosable.","Provide an opt-out flag for USER_PROMPT_SUBMIT hooks during troubleshooting."],"tags":["hooks","lifecycle","prompt"],"backgroundTag":"hook-blocked-prompt","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}