Repository navigation
Python: Reject Gemini candidate_count other than 1, including zero - #10188
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit intoNov 11, 2026
Conversation
Both the streaming and non-streaming parsers read candidates[0] only, so any candidate_count other than one is billed while every candidate but the first is silently dropped. Reject the option up front in _prepare_config unless it equals 1 (int or the stringified form, which is normalized), mirroring the Ollama client's explicit rejection of unsupported options. Zero is rejected along with counts above one. Replaces microsoft#9929 with the semantics requested in its review. Fixes microsoft#9928 Co-Authored-By: ZCode <zcode@bigmodel.ai>
Wilson_Jiang (Wilson0511)
temporarily deployed
to
github-app-auth
November 9, 2026 11:30 — with
GitHub Actions
Inactive
Wilson_Jiang (Wilson0511)
temporarily deployed
to
github-app-auth
November 9, 2026 11:30 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the Gemini candidate-count validation change.
No open issues 🎉
What changed in this PR
This PR addresses #9928 by rejecting unsupported Gemini candidate counts before requests are built, preventing responses from being silently truncated to the first candidate.
Changes:
- Rejects
candidate_countvalues other than1or"1", including zero. - Normalizes accepted values to integer
1and leaves the option unset when omitted. - Adds regression tests for rejected, accepted, and omitted values.
| File | Description |
|---|---|
python/packages/gemini/tests/test_gemini_client.py |
Adds candidate-count validation and normalization tests. |
python/packages/gemini/agent_framework_gemini/_chat_client.py |
Validates and normalizes candidate counts during config preparation. |
Review effort: Balanced
Member
|
Wilson_Jiang (@Wilson0511), the current-head code review is clean and checks are green. Before approval, please update the PR description to complete the repository template's Contribution Checklist, including contribution-guideline compliance, the agreed-issue/no-competing-PR attestation, and breaking-change status. The missing AI Assistance checkbox alone is not a blocker. |
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Nov 11, 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.
Python: Reject Gemini
candidate_countother than 1, including zeroFixes #9928
Replaces #9929 with the semantics requested in its review (apologies for the silence that let it close — picking it back up on current main).
Description
candidate_countstill flows to the Gemini API through the generic option passthrough, but both the streaming and non-streaming parsers readcandidates[0]only — any count other than one is billed for every candidate while all but the first are silently discarded. As noted in the #9929 review, the default should be to remove the option altogether, and if passed it needs to be1: zero (previously accepted) is rejected along with counts above one, and the stringified"1"some config paths produce is accepted and normalized to an int forGenerateContentConfig. The rejection raisesChatClientInvalidRequestExceptionup front in_prepare_config, mirroring the Ollama client's explicit rejection of unsupportedtool_choicemodes.Regression tests
test_candidate_count_other_than_one_is_rejected— parametrized over0,"0",2,"2",-1: all rejected before the request is built (red on current main: the option flows through untouched)test_candidate_count_one_passes_through_normalized—1and"1"both accepted, config carries the inttest_candidate_count_absent_leaves_config_unset— no option, no config fieldFull
test_gemini_client.py: 217 passed, 9 skipped, zero regressions. Analysis, fix and tests were prepared with AI assistance; the push and this PR are my own review and action.