Skip to content

[BUG] Model sometimes returns only text → causes "No image generated" error #2

@rens23

Description

@rens23

In ai_utils.py the gemini model is called with

response_modalities=['TEXT', 'IMAGE']

This allows the model to also only return text.
Current implementation assumes an image will always be present, resulting in:

RuntimeError: No image generated by the model.

This causes failures any time the model decides not to output an image.

Possible solutions:

  1. Force the model to produce an image or
  2. Provide a clear error message instructing the user to refine the
    prompt
  3. Gracefully return text-only responses

Option A — Force the model to output images only

Change:

response_modalities=['TEXT', 'IMAGE']

to:

response_modalities=['IMAGE']

Option B — Add a helpful error message when no image is returned

Replace:

raise RuntimeError("No image generated by the model.")

with something like:

raise RuntimeError(
    "The model returned no image. Try improving your prompt with more explicit visual instructions, or include a style reference image to guide output."
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions