Comfy-Org/ComfyUI · error · ValueError

Claude declined to answer this request for safety reasons. R

Error message

Claude declined to answer this request for safety reasons. Rephrase the prompt or try a different model.

What it means

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.

Source

Thrown at comfy_api_nodes/nodes_anthropic.py:306

            content.extend(await _build_image_content_blocks(cls, image_tensors))
        content.append(AnthropicTextContent(text=prompt))

        response = await sync_op(
            cls,
            ApiEndpoint(path=ANTHROPIC_MESSAGES_ENDPOINT, method="POST"),
            response_model=AnthropicMessagesResponse,
            data=AnthropicMessagesRequest(
                model=CLAUDE_MODELS[model_label],
                max_tokens=max_tokens,
                messages=[AnthropicMessage(role=AnthropicRole.user, content=content)],
                system=system_prompt or None,
                temperature=temperature,
                thinking=thinking_cfg,
                output_config=output_cfg,
            ),
        )
        if response.stop_reason == "refusal":
            raise ValueError(
                "Claude declined to answer this request for safety reasons. "
                "Rephrase the prompt or try a different model."
            )
        return IO.NodeOutput(_get_text_from_response(response) or "Empty response from Claude model.")


class AnthropicExtension(ComfyExtension):
    @override
    async def get_node_list(self) -> list[type[IO.ComfyNode]]:
        return [ClaudeNode]


async def comfy_entrypoint() -> AnthropicExtension:
    return AnthropicExtension()

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Rephrase the prompt to remove the policy-triggering request (the error message's own suggestion).
  2. Try a different model label (different Claude models have different refusal sensitivity).
  3. Remove adversarial system prompts ('ignore safety guidelines' style instructions reliably trigger refusals).
  4. Handle the ValueError in the workflow to fail gracefully instead of crashing the graph.

Example fix

# before
result = claude_node(prompt="...exact same prompt...")

# after
try:
    result = claude_node(prompt=rephrased_safe_prompt)
except ValueError as e:
    if "declined to answer" in str(e):
        result = fallback_response
Defensive patterns

Strategy: try-catch

Try / catch

try:
    out = await claude_node(prompt=prompt)
except ValueError as e:
    if "declined to answer" in str(e):
        out = fallback_text  # or re-raise for user action

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/e7b14640a53322f7. Report an issue: GitHub.