{"record":{"id":"f5d5e52fb55faa59","repo":"Comfy-Org/ComfyUI","slug":"gemini-did-not-generate-an-image-try-rephrasing-y","errorCode":null,"errorMessage":"Gemini did not generate an image. Try rephrasing your prompt or changing the response modality to 'IMAGE+TEXT' to see the model's reasoning.","messagePattern":"Gemini did not generate an image\\. Try rephrasing your prompt or changing the response modality to 'IMAGE\\+TEXT' to see the model's reasoning\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_gemini.py","lineNumber":231,"sourceCode":"async def get_image_from_response(response: GeminiGenerateContentResponse, thought: bool = False) -> Input.Image:\n    image_tensors: list[Input.Image] = []\n    parts = get_parts_by_type(response, \"image/*\")\n    for part in parts:\n        if (part.thought is True) != thought:\n            continue\n        if part.inlineData:\n            image_data = base64.b64decode(part.inlineData.data)\n            returned_image = bytesio_to_image_tensor(BytesIO(image_data))\n        else:\n            returned_image = await download_url_to_image_tensor(part.fileData.fileUri)\n        image_tensors.append(returned_image)\n    if len(image_tensors) == 0:\n        if not thought:\n            # No images generated --> extract text response for a meaningful error\n            model_message = get_text_from_response(response).strip()\n            if model_message:\n                raise ValueError(f\"Gemini did not generate an image. Model response: {model_message}\")\n            raise ValueError(\n                \"Gemini did not generate an image. \"\n                \"Try rephrasing your prompt or changing the response modality to 'IMAGE+TEXT' \"\n                \"to see the model's reasoning.\"\n            )\n        return torch.zeros((1, 1024, 1024, 4))\n    return torch.cat(image_tensors, dim=0)\n\n\ndef get_text_from_interaction(interaction: GeminiInteraction) -> str:\n    \"\"\"Extract and concatenate all model output text from an Interactions API response.\"\"\"\n    texts = []\n    for step in interaction.steps or []:\n        if step.type != \"model_output\":\n            continue\n        for content in step.content or []:\n            if content.type == \"text\" and content.text:\n                texts.append(content.text)\n    return \"\\n\".join(texts)","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_gemini.py#L213-L249","documentation":"Raised by the Gemini image generation node when the API response contains zero image parts (no inlineData and no fileData across all candidates) and the model also returned no text. This means Gemini accepted the request but declined or failed to produce any image payload, typically due to safety filtering or a prompt it could not interpret as an image request. The error explicitly suggests switching the response modality to 'IMAGE+TEXT' so the model's reasoning becomes visible in the text output.","triggerScenarios":"Calling a Gemini image node (e.g. GeminiImageGenerator image-only path) where the response has no inlineData/fileData parts, get_number_of_images-producing batches come back empty, and get_text_from_response(response).strip() is empty. Typical with response modality set to IMAGE only while the prompt triggers a safety refusal, or when the model answers with thought tokens but no visible output.","commonSituations":"Prompts with person/celebrity/copyright-adjacent content that Gemini's safety filters refuse; requests that the model interprets as a text question rather than an image request; intermittent provider-side refusals that return nothing on retry; using modality IMAGE where the model wants to explain why it refused.","solutions":["Change the response modality from 'IMAGE' to 'IMAGE+TEXT' and rerun — the text output will usually state why no image was produced.","Rephrase the prompt to be an explicit image-generation instruction and remove terms likely to trip safety filters.","Retry the same prompt; transient refusals with empty responses often succeed on a second attempt.","If a text explanation is returned instead (different branch), follow that model_message guidance."],"exampleFix":"// before\nresp = await api_generate_image(prompt, modality=\"IMAGE\")\nimage = images_from_response(resp)  # raises: Gemini did not generate an image...\n\n// after\nresp = await api_generate_image(prompt, modality=\"IMAGE+TEXT\")\nif not resp_has_image_parts(resp):\n    raise RuntimeError(f\"no image; model said: {get_text_from_response(resp)}\")\nimage = images_from_response(resp)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    images = await gemini_image_generate(prompt, modality=\"IMAGE\")\nexcept ValueError as e:\n    if \"did not generate an image\" in str(e):\n        retry_with_text = await gemini_image_generate(prompt, modality=\"IMAGE+TEXT\")\n        # inspect text output for refusal reason; surface to user\n    else:\n        raise","preventionTips":["Default the modality to IMAGE+TEXT during development so refusals return readable reasons.","Avoid prompt terms known to trip image safety filters in production modality=IMAGE workflows.","Wrap generation in a single retry with a rephrased prompt before surfacing failure to the user."],"tags":["gemini","image-generation","content-filter","comfy-api-nodes"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}