8 views
-/https://github.com/berriai/litellm/issues/28989
GitHub Β· issue

#28989 [Bug]: Gemini image generation silently drops finishReason on safety blocks

  • State: open
  • Author: @mehdi-ghaeini
  • Labels: llm translation

## Summary

When Gemini's image-generation endpoint returns `finishReason: IMAGE_SAFETY` / `IMAGE_PROHIBITED_CONTENT`, LiteLLM discards the `finishReason` and returns an empty `ImageResponse` with no exception. Downstream code can't tell "safety refusal" from "unrelated failure".

The chat-completion path was fixed by #20524 (which closed #20357), but only patched `vertex_and_google_ai_studio_gemini.py`. The image-gen transformation files were never updated.

## Affected (verified 2026-05-27)

- `main` and `v1.86.1` - Files: `litellm/llms/gemini/image_generation/transformation.py`, `litellm/llms/vertex_ai/image_generation/vertex_gemini_transformation.py`

Both iterate `candidates[].content.parts[]` for `inlineData`, ignoring `finishReason`. Grep for `finish|safety|prohibit|content_filter|_hidden_params` in either file returns zero matches.

## Reproduction

```python response = await litellm.aimage_generation( model="gemini/gemini-2.5-flash-image", prompt="turn this person into Yoda", ) # response.data == [] # no exception ```

Underlying Gemini response contains `candidates[0].finishReason: "IMAGE_PROHIBITED_CONTENT"` β€” lost.

## Suggested fix

Per #21348 Criterion 2 β€” pre…

GitHub resolver

Import GitHub neighbors on demand. Results are saved as system ingests.

Refresh page
vote history (1 events)
#0 of 0 Β· 31d18h3m37s ago β€” entered Β· #import:https:::github.com:berriai:litellm post #2793
#33955 requires cross-cutting changes to batch processing, buffering, concurrency, resource limits, and regression coverage, with significant production-risk around large payloads and worker coordination. #28989 is comparatively localized to response translation and error propagation in two provider-specific paths.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search