Comfy-Org/ComfyUI · error · ValueError

Gemini API blocked the request. Reason: {feedback.blockReaso

Error message

Gemini API blocked the request. Reason: {feedback.blockReason} ({feedback.blockReasonMessage})

What it means

Raised while extracting parts from a Gemini generateContent response when response.candidates is empty AND response.promptFeedback.blockReason is set. This is Google's server-side prompt safety filter blocking the request before generation; both the machine-readable blockReason and the human-readable blockReasonMessage are surfaced.

Source

Thrown at comfy_api_nodes/nodes_gemini.py:170

        return False
    return fnmatch(mime.value, pattern)


def get_parts_by_type(response: GeminiGenerateContentResponse, part_type: Literal["text"] | str) -> list[GeminiPart]:
    """
    Filter response parts by their type.

    Args:
        response: The API response from Gemini.
        part_type: Type of parts to extract ("text" or a MIME type).

    Returns:
        List of response parts matching the requested type.
    """
    if not response.candidates:
        if response.promptFeedback and response.promptFeedback.blockReason:
            feedback = response.promptFeedback
            raise ValueError(
                f"Gemini API blocked the request. Reason: {feedback.blockReason} ({feedback.blockReasonMessage})"
            )
        raise ValueError(
            "Gemini API returned no response candidates. If you are using the `IMAGE` modality, "
            "try changing it to `IMAGE+TEXT` to view the model's reasoning and understand why image generation failed."
        )
    parts = []
    blocked_reasons = []
    for candidate in response.candidates:
        if candidate.finishReason and candidate.finishReason.upper() == "IMAGE_PROHIBITED_CONTENT":
            blocked_reasons.append(candidate.finishReason)
            continue
        if candidate.content is None or candidate.content.parts is None:
            continue
        for part in candidate.content.parts:
            if part_type == "text" and part.text:
                parts.append(part)
            elif part.inlineData and _mime_matches(part.inlineData.mimeType, part_type):

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Match the blockReason name to the cause: SAFETY -> rephrase prompt; COPYRIGHT -> remove celebrity/brand-style references; OTHER -> simplify and retry.
  2. Remove or replace reference images that may be triggering the filter.
  3. If the content is legitimate (medical, news, security research), add clinical/professional framing to the prompt.
  4. Adjust the node's safety settings if exposed, then retry.
Defensive patterns

Strategy: try-catch

Try / catch

try:
    parts = extract_parts(response, "text")
except ValueError as e:
    if "blocked the request" in str(e):
        # prompt-level block: rephrase or swap images; retrying unchanged will fail again
        raise PolicyBlocked(str(e)) from e
    raise

Prevention

When it happens

Trigger: Gemini API returns no candidates with promptFeedback.blockReason such as SAFETY, LANGUAGE, COPYRIGHT, or PROHIBITED_CONTENT — triggered by the prompt text, inline image content, or system instruction.

Common situations: Prompts with violence/sexual/political content; requests about real people that trip COPYRIGHT depictions filters; images with disallowed content attached as reference; aggressive safetySettings configured upstream.

Related errors


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