{"record":{"id":"9fc562dd83ad37fb","repo":"zed-industries/zed","slug":"the-agent-refused-to-process-that-prompt-try-again","errorCode":null,"errorMessage":"The agent refused to process that prompt. Try again.","messagePattern":"The agent refused to process that prompt\\. Try again\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/agent/src/agent.rs","lineNumber":3538,"sourceCode":"                        Err(anyhow!(\n                            \"The agent is nearing the end of its context window and has been \\\n                             stopped. You can prompt the thread again to have the agent wrap up \\\n                             or hand off its work.\"\n                        ))\n                    }\n                }\n            };\n            let discard_partial_output = matches!(\n                &response,\n                Ok(Some(response)) if response.stop_reason == acp::StopReason::Cancelled\n                    || response.stop_reason == acp::StopReason::Refusal\n            );\n            let result = match response {\n                Ok(Some(response)) => match response.stop_reason {\n                    acp::StopReason::Cancelled => Err(anyhow!(\"User canceled\")),\n                    acp::StopReason::MaxTokens => Err(anyhow!(\"The agent reached the maximum number of tokens.\")),\n                    acp::StopReason::MaxTurnRequests => Err(anyhow!(\"The agent reached the maximum number of allowed requests between user turns. Try prompting again.\")),\n                    acp::StopReason::Refusal => Err(anyhow!(\"The agent refused to process that prompt. Try again.\")),\n                    _ => thread.read_with(cx, |thread, _cx| {\n                        thread\n                            .last_message()\n                            .and_then(|message| {\n                                let content = message.as_agent_message()?\n                                    .content\n                                    .iter()\n                                    .filter_map(|content| match content {\n                                        AgentMessageContent::Text(text) => Some(text.as_str()),\n                                        _ => None,\n                                    })\n                                    .join(\"\\n\\n\");\n                                if content.is_empty() {\n                                    None\n                                } else {\n                                    Some(content)\n                                }\n                            })","sourceCodeStart":3520,"sourceCodeEnd":3556,"githubUrl":"https://github.com/zed-industries/zed/blob/916fc2b8cb3a815cbef4a3b40e13081be72036b6/crates/agent/src/agent.rs#L3520-L3556","documentation":"Mapped from ACP StopReason::Refusal: the model (or provider safety layer) declined to process the prompt, so no agent output is produced. Any partial output from the refusal is discarded and this error is returned to the parent thread.","triggerScenarios":"A subagent prompt (or content it reads, e.g. tool outputs) trips the model/provider's safety refusal path, causing the response to end with stop_reason=Refusal rather than EndTurn.","commonSituations":"Prompts phrased in ways classifiers flag (malware, credential extraction, explicit content); repositories whose contents trigger false-positive refusals; aggressive provider-side safety filters.","solutions":["Rephrase the prompt more precisely and neutrally, stating the legitimate engineering intent","Split the prompt so sensitive-looking but benign steps are separated","Retry the request; transient classifier false positives may resolve on retry","If content in the repo triggers it, avoid feeding that specific file/content to the agent","Switch to a model/provider with a different safety policy"],"exampleFix":"// before\nthread.send(\"Extract all the passwords and tokens you can find in this repo\");\n\n// after\nthread.send(\"Find any hardcoded credentials that would fail our security audit scan and list their file locations\");","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match subagent_result {\n    Err(e) if e.to_string().contains(\"refused to process that prompt\") => {\n        // rephrase the prompt and retry once before surfacing to the user\n    }\n    other => other?,\n}","preventionTips":["Phrase prompts with clear, legitimate engineering intent","Avoid prompts or inputs that resemble sensitive content extraction","Test prompts against the target model's safety policy when automating","Keep a fallback rephrasing ready for refusal-prone tasks"],"tags":["agent","llm","safety-refusal"],"backgroundTag":"upstream-api-error","analyzedSha":"916fc2b8cb3a815cbef4a3b40e13081be72036b6","analyzedAt":"2026-09-19T19:09:50.599Z","contentChangedAt":"2026-09-19T19:09:50.599Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}