Comfy-Org/ComfyUI · error · ValueError
Gemini API blocked the request. Reasons: {blocked_reasons}
Error message
Gemini API blocked the request. Reasons: {blocked_reasons} What it means
Raised when the Gemini response DID contain candidates, but every one finished with finishReason == 'IMAGE_PROHIBITED_CONTENT' and no usable parts were extracted. This is the per-candidate safety outcome for image generation: the prompt was accepted, the model ran, but the requested image content was classified as prohibited and suppressed.
Source
Thrown at comfy_api_nodes/nodes_gemini.py:194
)
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):
parts.append(part)
elif part.fileData and _mime_matches(part.fileData.mimeType, part_type):
parts.append(part)
if not parts and blocked_reasons:
raise ValueError(f"Gemini API blocked the request. Reasons: {blocked_reasons}")
return parts
def get_text_from_response(response: GeminiGenerateContentResponse) -> str:
"""
Extract and concatenate all text parts from the response.
Args:
response: The API response from Gemini.
Returns:
Combined text from all text parts in the response.
"""
parts = get_parts_by_type(response, "text")
return "\n".join([part.text for part in parts])
View on GitHub (pinned to 1c6d8d45b3)
Solutions
- Soften or abstract the prohibited elements of the prompt (avoid real people, explicit violence, brand characters).
- Reframe as illustration styles or fictional subjects rather than realistic depictions.
- Retry with minor wording changes — the output filter has non-deterministic thresholds.
- Combine with IMAGE+TEXT modality to see any model-side explanation.
Defensive patterns
Strategy: try-catch
Try / catch
try:
parts = extract_parts(response, "image")
except ValueError as e:
if "IMAGE_PROHIBITED_CONTENT" in str(e):
# output-level filter: soften the prompt; do not retry identically
raise ProhibitedImage(str(e)) from e
raise Prevention
- Avoid real-person likenesses, explicit violence, and trademarked characters in image prompts.
- Reframe prohibited subjects as stylized/fictional equivalents.
- Expect non-deterministic thresholds — minor rewording can pass.
When it happens
Trigger: One or more candidates with finishReason IMAGE_PROHIBITED_CONTENT are collected into blocked_reasons, the parts list ends up empty, and the extractor raises with the list of finish reasons.
Common situations: Image prompts about real public figures, violent or sexual imagery, trademarked characters, or borderline content that passes prompt-level filters but fails output-level ones; imagedepict requests the safety layer flags post-generation.
Related errors
- Gemini API blocked the request. Reason: {feedback.blockReaso
- Gemini API returned no response candidates. If you are using
- Gemini did not generate an image. Model response: {model_mes
- Seed Audio returned no audio (code={response.code}): {respon
- Model refused to respond: {block.refusal}
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/000edb20641c5e59.
Report an issue: GitHub.