Skip to main content

Overview

gemini-3-pro-image-preview (i.e., Nano Banana Pro) enforces strict content safety controls and will reject non-compliant requests at multiple layers. A simple “generation failed” message doesn’t help users understand the problem. Good error handling needs to:
  • Accurately identify the rejection reason — distinguish between content violations, knowledge-base limits, and technical errors
  • Provide friendly user messaging — turn technical errors into understandable explanations
  • Offer actionable suggestions — tell users how to adjust their request to succeed
  • Retain complete technical details — for developer debugging
When a request returns HTTP 200 but no image, this is usually a safety judgment made on Google’s side. APIYI’s transparent proxy simply forwards the result as-is — we want our customers to generate images successfully too. The detection and messaging logic must be implemented on your application side.

Google Content Moderation Policy (2026 Update)

Google’s image generation uses a two-layer safety mechanism:
  1. Configurable filters: cover four categories — harassment, hate speech, sexually explicit content, and dangerous content — adjustable via safetySettings
  2. Built-in protections: always active for core harms (such as child safety) and cannot be disabled via parameters
Explicitly prohibited content includes: child sexual abuse and exploitation (CSAE), violent extremism/terrorism, non-consensual intimate imagery (NCII), self-harm, sexually explicit content, hate speech, and harassment and bullying.
In February 2026, after Nano Banana 2 launched, Google significantly tightened its policies around people and copyright, adding/strengthening the following frequent rejection scenarios (data as of May 2026 (UTC+8)):
  • Public figures / celebrities: photorealistic, recognizable real people
  • Face swap (faceswap)
  • Re-dressing / face-altering real people
  • Tampering with financial or order information
  • Well-known IP (such as Disney, since January 23, 2026)
  • Watermark removal and minor-related content
Still allowed: fictional characters, stylized portraits, and illustrated figures.
Google’s official policy documents (please copy and visit them yourself):
  • Generative AI Prohibited Use Policy: policies.google.com/terms/generative-ai/use-policy
  • Generative content common errors reference: ai.google.dev/api/generate-content

Three Core Diagnostic Indicators

Check in order of priority, from highest to lowest:

1. candidatesTokenCount (highest priority) ⭐

  • Location: response.usageMetadata.candidatesTokenCount
  • Meaning: the token count of candidate content generated by the API
  • Rule: a value of 0 means the request was rejected outright at the content moderation stage — no candidate content was even generated. This is the strictest rejection.

2. finishReason (second priority)

  • Location: response.candidates[0].finishReason
  • Rule: any value other than STOP indicates an abnormal completion that requires special handling
The latest image-related finishReason values (note that the Nano Banana series added image-specific values with the IMAGE_ prefix):

3. Text rejection explanation (important)

  • Location: response.candidates[0].content.parts[].text
  • Rule: when finishReason is STOP but parts contains only text and no image data, the API has returned a rejection explanation rather than an image. The text may be in Chinese or English, for example:

Error Scenario Quick Reference

Handling Flow (Decision Order)

Code Implementation (Core)

Combine the checks above into a single parsing function:
Smart keyword detection (optional, for more specific messaging):
The most common pitfall: a part carrying thoughtSignature may still contain important text. Always collect the text first, then decide whether to skip — otherwise the rejection explanation is lost and users only see “generation failed.”

Consumer-Friendly Messaging

Design principles: clear and concise, positive guidance, actionable, no blame. Recommended templates:
Tiered display recommendations:
  • Consumer users: by default show only the friendly explanation + revision suggestion
  • Business / tool providers: by default expand technical details (finishReason, candidatesTokenCount, etc.)
  • Developers: provide an “expand/collapse” toggle to view the full JSON response

Best Practices

  1. Check strictly by priority: candidatesTokenCountfinishReasonparts → extract data → keyword detection
  2. Collect text before checking thoughtSignature to avoid losing the rejection explanation
  3. Keep the full response: development/testing tools should always save the raw JSON for troubleshooting
  4. Support Chinese and English rejection text: Google may return Chinese or English, so keyword matching must cover both
  5. Graceful degradation: give a specific message when smart detection succeeds; otherwise show the API text directly; otherwise use the friendly finishReason name; and only then fall back to a generic message
  6. Never show “unknown error”: always include an actionable suggestion or the full response

FAQ

Google’s safety filtering has randomness and context dependence: reference image content and how the prompt is combined all affect the judgment. Try adjusting the wording or using more indirect phrasing.
candidatesTokenCount: 0 or finishReason: PROHIBITED_CONTENT → content problem; Failed to fetch or an HTTP error → technical problem; an API text explanation → usually a content problem.
Tiered display: by default show the friendly explanation + revision suggestion; optionally expand technical details; in development mode show the full JSON response.
No. A mapping table plus a generic fallback is enough: reasonMessages[finishReason] || then display the raw value.