Skip to content

fix: raise on Gemini responses with no text content - #516

Closed
uuzzrm wants to merge 1 commit into
google:mainfrom
uuzzrm:fix/gemini-no-text-response
Closed

uuzzrm wants to merge 1 commit into
google:mainfrom
uuzzrm:fix/gemini-no-text-response

Conversation

@uuzzrm

@uuzzrm uuzzrm commented Aug 15, 2026 •

Copy link
Copy Markdown

Description

The Gemini realtime path returned a "successful" empty extraction when a prompt was blocked or a candidate stopped without producing text: GenerateContentResponse.text is None for safety-blocked prompts, candidates with a non-STOP finish reason, and non-text-only responses, and _process_single_prompt happily returned ScoredOutput(score=1.0, output=None). The caller gets no signal that anything was blocked, and the actual reason (prompt_feedback.block_reason / candidates[0].finish_reason) is silently discarded.

This mirrors the guard already applied to the OpenAI provider (#496): when response.text is None, _process_single_prompt now raises InferenceRuntimeError with the available block/finish reason, and the error propagates unwrapped (not retried, not wrapped in "Gemini API error").

Fixes #508

How Has This Been Tested?

Added TestGeminiNoTextResponseHandling to tests/gemini_retry_test.py covering:

  • a normal text response still returns ScoredOutput
  • a blocked prompt (prompt_feedback.block_reason) raises with the block reason
  • an empty candidate (finish_reason) raises with the finish reason
  • a no-text response is never retried
  • the InferenceRuntimeError propagates unwrapped
pytest tests/gemini_retry_test.py

Also ran the full unit suite locally: 767 passed. The 10 failures observed are Windows-only (symlink/pip tests in create_provider_plugin_test.py), unrelated to this change.

Checklist:

  • I have read and acknowledged Google's Open Source Code of conduct.
  • I have read the Contributing page, and I either signed the Google Individual CLA or am covered by my company's Corporate CLA.
  • I have discussed my proposed solution with code owners in the linked issue(s) and we have agreed upon the general approach.
  • I have made any needed documentation changes, or noted in the linked issue(s) that documentation elsewhere needs updating.
  • I have added tests, or I have ensured existing tests cover the changes
  • I have followed Google's Python Style Guide and ran pylint over the affected code.

@github-actions github-actions Bot added the size/S Pull request with 50-150 lines changed label Aug 15, 2026
@uuzzrm

uuzzrm commented Aug 15, 2026

Copy link
Copy Markdown
Author

Heads up on the remaining red check: the repo’s “linked issue with community support” workflow needs 5 👍 on #508 before it goes green, and the issue currently has none. If this bug has bitten anyone here, a thumbs-up on the issue would help get it merged.

@uuzzrm

uuzzrm commented Aug 15, 2026

Copy link
Copy Markdown
Author

Heads up on the red enforce check: it's the community-support gate, not the code. The linked-issue workflow requires 5 thumbs-up reactions on #508 from unique users (the PR author's own reaction doesn't count), and that issue is fresh with zero reactions so far. I've posted on the issue asking people who hit the empty-success bug to react - once it clears 5, the check should go green on re-run. The code checks themselves (test, format, check) all pass.

@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 1 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

1 similar comment
@github-actions

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 1 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

⚠️ Branch Update Required

Your branch is 1 commits behind main. Please update your branch to ensure CI checks run with the latest code:

git fetch origin main
git merge origin/main
git push

Note: Enable "Allow edits by maintainers" to allow automatic updates.

@aksg87

aksg87 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Thanks @uuzzrm for the contribution! This fix is covered by the merged #534, which credits this PR and adds coverage for related response failures. Closing this PR as superseded; we appreciate your work on it.

@aksg87 aksg87 closed this Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Pull request with 50-150 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Gemini realtime path returns empty success (score=1.0, output=None) on a safety-blocked or refused response

2 participants