{"record":{"id":"eb5a6c757caac2d6","repo":"Comfy-Org/ComfyUI","slug":"gemini-api-blocked-the-request-reason-feedback","errorCode":null,"errorMessage":"Gemini API blocked the request. Reason: {feedback.blockReason} ({feedback.blockReasonMessage})","messagePattern":"Gemini API blocked the request\\. Reason: (.+?) \\((.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_gemini.py","lineNumber":170,"sourceCode":"        return False\n    return fnmatch(mime.value, pattern)\n\n\ndef get_parts_by_type(response: GeminiGenerateContentResponse, part_type: Literal[\"text\"] | str) -> list[GeminiPart]:\n    \"\"\"\n    Filter response parts by their type.\n\n    Args:\n        response: The API response from Gemini.\n        part_type: Type of parts to extract (\"text\" or a MIME type).\n\n    Returns:\n        List of response parts matching the requested type.\n    \"\"\"\n    if not response.candidates:\n        if response.promptFeedback and response.promptFeedback.blockReason:\n            feedback = response.promptFeedback\n            raise ValueError(\n                f\"Gemini API blocked the request. Reason: {feedback.blockReason} ({feedback.blockReasonMessage})\"\n            )\n        raise ValueError(\n            \"Gemini API returned no response candidates. If you are using the `IMAGE` modality, \"\n            \"try changing it to `IMAGE+TEXT` to view the model's reasoning and understand why image generation failed.\"\n        )\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):","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_gemini.py#L152-L188","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Match the blockReason name to the cause: SAFETY -> rephrase prompt; COPYRIGHT -> remove celebrity/brand-style references; OTHER -> simplify and retry.","Remove or replace reference images that may be triggering the filter.","If the content is legitimate (medical, news, security research), add clinical/professional framing to the prompt.","Adjust the node's safety settings if exposed, then retry."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    parts = extract_parts(response, \"text\")\nexcept ValueError as e:\n    if \"blocked the request\" in str(e):\n        # prompt-level block: rephrase or swap images; retrying unchanged will fail again\n        raise PolicyBlocked(str(e)) from e\n    raise","preventionTips":["Keep prompts and attached images inside Gemini's content policy.","Map blockReason names (SAFETY, COPYRIGHT, ...) to concrete prompt changes instead of blind retries.","In automated pipelines, catch block errors and route to a sanitized-prompt fallback."],"tags":["comfyui","gemini","content-moderation","safety-filter","api-error"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}