{"record":{"id":"000edb20641c5e59","repo":"Comfy-Org/ComfyUI","slug":"gemini-api-blocked-the-request-reasons-blocked","errorCode":null,"errorMessage":"Gemini API blocked the request. Reasons: {blocked_reasons}","messagePattern":"Gemini API blocked the request\\. Reasons: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_gemini.py","lineNumber":194,"sourceCode":"        )\n    parts = []\n    blocked_reasons = []\n    for candidate in response.candidates:\n        if candidate.finishReason and candidate.finishReason.upper() == \"IMAGE_PROHIBITED_CONTENT\":\n            blocked_reasons.append(candidate.finishReason)\n            continue\n        if candidate.content is None or candidate.content.parts is None:\n            continue\n        for part in candidate.content.parts:\n            if part_type == \"text\" and part.text:\n                parts.append(part)\n            elif part.inlineData and _mime_matches(part.inlineData.mimeType, part_type):\n                parts.append(part)\n            elif part.fileData and _mime_matches(part.fileData.mimeType, part_type):\n                parts.append(part)\n\n    if not parts and blocked_reasons:\n        raise ValueError(f\"Gemini API blocked the request. Reasons: {blocked_reasons}\")\n\n    return parts\n\n\ndef get_text_from_response(response: GeminiGenerateContentResponse) -> str:\n    \"\"\"\n    Extract and concatenate all text parts from the response.\n\n    Args:\n        response: The API response from Gemini.\n\n    Returns:\n        Combined text from all text parts in the response.\n    \"\"\"\n    parts = get_parts_by_type(response, \"text\")\n    return \"\\n\".join([part.text for part in parts])\n\n","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_gemini.py#L176-L212","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    parts = extract_parts(response, \"image\")\nexcept ValueError as e:\n    if \"IMAGE_PROHIBITED_CONTENT\" in str(e):\n        # output-level filter: soften the prompt; do not retry identically\n        raise ProhibitedImage(str(e)) from e\n    raise","preventionTips":["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."],"tags":["comfyui","gemini","content-moderation","image-generation","safety-filter"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}