{"record":{"id":"e7b14640a53322f7","repo":"Comfy-Org/ComfyUI","slug":"claude-declined-to-answer-this-request-for-safety","errorCode":null,"errorMessage":"Claude declined to answer this request for safety reasons. Rephrase the prompt or try a different model.","messagePattern":"Claude declined to answer this request for safety reasons\\. Rephrase the prompt or try a different model\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_anthropic.py","lineNumber":306,"sourceCode":"            content.extend(await _build_image_content_blocks(cls, image_tensors))\n        content.append(AnthropicTextContent(text=prompt))\n\n        response = await sync_op(\n            cls,\n            ApiEndpoint(path=ANTHROPIC_MESSAGES_ENDPOINT, method=\"POST\"),\n            response_model=AnthropicMessagesResponse,\n            data=AnthropicMessagesRequest(\n                model=CLAUDE_MODELS[model_label],\n                max_tokens=max_tokens,\n                messages=[AnthropicMessage(role=AnthropicRole.user, content=content)],\n                system=system_prompt or None,\n                temperature=temperature,\n                thinking=thinking_cfg,\n                output_config=output_cfg,\n            ),\n        )\n        if response.stop_reason == \"refusal\":\n            raise ValueError(\n                \"Claude declined to answer this request for safety reasons. \"\n                \"Rephrase the prompt or try a different model.\"\n            )\n        return IO.NodeOutput(_get_text_from_response(response) or \"Empty response from Claude model.\")\n\n\nclass AnthropicExtension(ComfyExtension):\n    @override\n    async def get_node_list(self) -> list[type[IO.ComfyNode]]:\n        return [ClaudeNode]\n\n\nasync def comfy_entrypoint() -> AnthropicExtension:\n    return AnthropicExtension()\n","sourceCodeStart":288,"sourceCodeEnd":321,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_anthropic.py#L288-L321","documentation":"After a successful Anthropic Messages API call, the node inspects response.stop_reason; a value of 'refusal' means Claude's safety systems declined to produce content for this prompt. The node converts the API-level refusal into a local ValueError with actionable guidance.","triggerScenarios":"POST to ANTHROPIC_MESSAGES_ENDPOINT where the model returns stop_reason='refusal' — typically prompts requesting disallowed content, malicious code, or content violating the usage policy, regardless of system_prompt or thinking config.","commonSituations":"Prompt engineering near policy boundaries; safety-triggering words accidentally included; using a system prompt that tries to override safety guidelines; switching from another model that answered the same prompt.","solutions":["Rephrase the prompt to remove the policy-triggering request (the error message's own suggestion).","Try a different model label (different Claude models have different refusal sensitivity).","Remove adversarial system prompts ('ignore safety guidelines' style instructions reliably trigger refusals).","Handle the ValueError in the workflow to fail gracefully instead of crashing the graph."],"exampleFix":"# before\nresult = claude_node(prompt=\"...exact same prompt...\")\n\n# after\ntry:\n    result = claude_node(prompt=rephrased_safe_prompt)\nexcept ValueError as e:\n    if \"declined to answer\" in str(e):\n        result = fallback_response","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    out = await claude_node(prompt=prompt)\nexcept ValueError as e:\n    if \"declined to answer\" in str(e):\n        out = fallback_text  # or re-raise for user action","preventionTips":["Keep prompts clear of policy-triggering requests.","Provide a workflow-level fallback output for refused generations.","Do not use system prompts that attempt to bypass safety; they increase refusals."],"tags":["anthropic","claude","safety","refusal","content-policy"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}