Repository navigation
Python: Report content_filter when Gemini blocks the prompt - #10213
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit intoNov 10, 2026
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
Conversation
Signed-off-by: NNIIOVO <haimingni44@gmail.com>
ni (nniiovoo)
temporarily deployed
to
github-app-auth
November 9, 2026 18:40 — with
GitHub Actions
Inactive
ni (nniiovoo)
temporarily deployed
to
github-app-auth
November 9, 2026 18:41 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change that distinguishes Gemini-blocked prompts from empty answers.
No open issues 🎉
What changed in this PR
This PR fixes #10212 by making the Python Gemini client report content_filter when Gemini blocks a prompt, distinguishing blocked requests from empty answers.
Changes:
- Share finish-reason handling across streaming and non-streaming responses while preserving existing candidate finish reasons.
- Retain streaming usage when a prompt is blocked.
- Add regression tests for blocked prompts and blocked continuation hops in both modes, and correct the mock’s default prompt feedback.
| File | Description |
|---|---|
python/packages/gemini/tests/test_gemini_client.py |
Adds blocked-response coverage and sets mock prompt feedback to None. |
python/packages/gemini/agent_framework_gemini/_chat_client.py |
Adds shared finish-reason resolution that recognizes prompt blocking on both response paths. |
Review effort: Balanced
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Nov 10, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
When Gemini blocks the prompt itself, the response has no candidates and only
prompt_feedback.block_reason. The client returned an empty message withfinish_reason=None, so callers can't tell a blocked prompt from an empty answer, and streaming also dropped the usage. Repro is in #10212.Description & Review Guide
_response_finish_reasonhelper, used by both_process_generate_responseand_process_chunk. It returns the mapped candidate finish reason as before, andcontent_filterwhen the candidate has no finish reason andprompt_feedback.block_reasonis set. Usually a blocked prompt has no candidates, but when a later automatic-continuation hop is blocked the SDK keeps the earlier candidate with itsfinish_reasoncleared, so that case is covered too.finish_reason="content_filter"on both paths, and the streamed response keeps its usage. Responses where the candidate has a finish reason are unchanged.prompt_feedbackfromraw_representation. Happy to change it if you'd rather raise.Tests: I added tests for a blocked prompt and a blocked continuation hop, on both paths (they fail on main). I also set
prompt_feedback = Nonein the_make_responsetest helper, since a MagicMock attribute is always truthy.Related Issue
Fixes #10212
AI Assistance
AI assistance details: issue analysis, implementation, tests, and this description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.