Comfy-Org/ComfyUI · error · ValueError

Gemini did not generate an image. Model response: {model_mes

Error message

Gemini did not generate an image. Model response: {model_message}

What it means

Raised by the Gemini image extractor when the response contained candidates and parts but zero usable images, and the model's text channel contains an explanation. The node extracts the text via get_text_from_response and embeds it, so the error doubles as the model's own refusal/failure reason. This is the 'model answered with words instead of an image' path for non-thought requests.

Source

Thrown at comfy_api_nodes/nodes_gemini.py:230

async def get_image_from_response(response: GeminiGenerateContentResponse, thought: bool = False) -> Input.Image:
    image_tensors: list[Input.Image] = []
    parts = get_parts_by_type(response, "image/*")
    for part in parts:
        if (part.thought is True) != thought:
            continue
        if part.inlineData:
            image_data = base64.b64decode(part.inlineData.data)
            returned_image = bytesio_to_image_tensor(BytesIO(image_data))
        else:
            returned_image = await download_url_to_image_tensor(part.fileData.fileUri)
        image_tensors.append(returned_image)
    if len(image_tensors) == 0:
        if not thought:
            # No images generated --> extract text response for a meaningful error
            model_message = get_text_from_response(response).strip()
            if model_message:
                raise ValueError(f"Gemini did not generate an image. Model response: {model_message}")
            raise ValueError(
                "Gemini did not generate an image. "
                "Try rephrasing your prompt or changing the response modality to 'IMAGE+TEXT' "
                "to see the model's reasoning."
            )
        return torch.zeros((1, 1024, 1024, 4))
    return torch.cat(image_tensors, dim=0)


def get_text_from_interaction(interaction: GeminiInteraction) -> str:
    """Extract and concatenate all model output text from an Interactions API response."""
    texts = []
    for step in interaction.steps or []:
        if step.type != "model_output":
            continue
        for content in step.content or []:
            if content.type == "text" and content.text:
                texts.append(content.text)

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Read the embedded model message — it is the model's stated reason for not producing an image.
  2. Rewrite the prompt as an image-generation instruction ('Generate an image of ...') rather than a question or conversation.
  3. Remove disallowed subjects if the message indicates a policy refusal.
  4. Verify the response modality includes IMAGE if you expect image output.

Example fix

// before: prompt = "Can you draw a cat?" (expecting an image)
// after:  prompt = "Generate an image of a cat sitting on a windowsill."
Defensive patterns

Strategy: try-catch

Try / catch

try:
    images = get_images_from_response(response)
except ValueError as e:
    if "did not generate an image" in str(e):
        # error text contains the model's own explanation; log it for the user
        log.warning("Gemini image generation failed: %s", e)
        raise

Prevention

When it happens

Trigger: image_tensors is empty after iterating parts, thought is falsy, and get_text_from_response(response).strip() is non-empty — e.g. the model replied 'I can't generate that' as text in an image request.

Common situations: Prompt phrased as a question so the model answers instead of drawing; model declining the subject; modality mismatch where text was requested but images extracted; edge cases where the model returns inline text alongside no inlineData/fileData parts.

Related errors


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