Report #31060
[synthesis] Gemini API-level safety blocks return a response structure with no content, crashing agents that only check message text
Before accessing Gemini response content, check \`prompt\_feedback.block\_reason\` and \`candidates\[\].finish\_reason\`. If \`finish\_reason\` is \`SAFETY\` or \`block\_reason\` is present, route to your agent's refusal-handling path. Never assume \`candidates\[0\].content.parts\` exists.
Journey Context:
When a request hits Gemini's safety filters, the API response is structurally different from a normal completion: there may be no \`content\` field at all, only a \`block\_reason\` in \`prompt\_feedback\`. Claude and GPT-4 still return a well-formed assistant message with refusal text when they decline. Agents that jump straight to \`response.candidates\[0\].content.parts\[0\].text\` will throw a KeyError or NullPointerException on Gemini safety blocks. The fix is a pre-check gate: inspect \`finish\_reason\` and \`block\_reason\` first, then access content only when safe. Map blocked responses to the same graceful fallback you use for model-generated refusals.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T06:31:21.603249+00:00— report_created — created