Skip to content

fix: revert person_generation auto-routing to warn-only (#14) - #15

Merged
Ahmed-aleryani merged 3 commits into
mainfrom
fix/person-generation-warn-only
Mar 29, 2026
Merged

fix: revert person_generation auto-routing to warn-only (#14)#15
Ahmed-aleryani merged 3 commits into
mainfrom
fix/person-generation-warn-only

Conversation

@Ahmed-aleryani

Copy link
Copy Markdown
Contributor

Summary

Reverts the smart auto-routing introduced in #14. Auto-routing silently swapped Gemini models for Imagen when person_generation was set, degrading quality (especially text rendering for Arabic/RTL) without user consent.

The problem: quality="quality" resolves to gemini-3-pro-image-preview (~94% text accuracy). When the calling LLM defensively adds person_generation="block", auto-routing swapped to imagen-4.0-ultra which has worse text rendering → garbled Arabic text.

The fix: Warn-only approach — always preserve the user's chosen model. Skip person_generation for Gemini with a clear warning explaining that Gemini blocks photorealistic identifiable people by default but still generates fictional/illustrated people, and suggesting Imagen models for strict API-level enforcement.

What changed

  • Removed GEMINI_TO_IMAGEN_MAP, IMAGEN_ASPECT_RATIOS, and auto-routing logic from generate()
  • Updated warning message with accurate info about Gemini's built-in person restrictions
  • Removed auto_routed response field from format_image_result()
  • Replaced 10 auto-routing tests with 2 focused warn-only tests (242 tests passing)

What stays from v0.5.1/v0.5.2

  • SDK enum fix: "block""DONT_ALLOW" (correct PersonGeneration member)
  • person_generation NOT passed to Gemini's ImageConfig (prevents ValueError)
  • person_generation works correctly for Imagen models via GenerateImagesConfig
  • genai Image → Pillow conversion in Imagen save paths
  • Gemini capabilities: person_generation: False, Imagen: True

Test plan

  • 242 unit tests passing
  • ruff/black clean
  • Manual test: generate_image(quality="quality", person_generation="block") generates on gemini-3-pro with warning (NOT Imagen)

Removed GEMINI_TO_IMAGEN_MAP, IMAGEN_ASPECT_RATIOS, and the entire
auto-routing block from generate(). The auto-routing silently swapped
Gemini models for Imagen when person_generation was set, degrading
quality (especially Arabic/RTL text rendering) without user consent.

Updated the warning message to accurately explain that Gemini blocks
photorealistic identifiable people by default but still generates
fictional/illustrated people, and suggests Imagen models for strict
API-level enforcement.
Removed auto_routed propagation from format_image_result() since the
field no longer exists in generation results. Updated the generate_image
docstring and server_info to reflect the warn-only behavior for
person_generation on Gemini models. Updated the person_generation field
description in validation.py to clarify enforcement scope.
Replaced TestPersonGenerationAutoRouting class (10 tests) with
TestPersonGenerationWarnOnly class (2 focused tests) that verify:
- person_generation on Gemini stays on Gemini (no silent model swap)
- person_generation on Gemini produces a warning pointing to Imagen

Removed auto_routed propagation test from test_server.py since the
field is no longer present in generation responses.

All 242 unit tests passing.
@Ahmed-aleryani Ahmed-aleryani added the bug Something isn't working label Mar 29, 2026
@Ahmed-aleryani Ahmed-aleryani self-assigned this Mar 29, 2026
@Ahmed-aleryani Ahmed-aleryani added the bug Something isn't working label Mar 29, 2026
@Ahmed-aleryani
Ahmed-aleryani merged commit e71db31 into main Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant