fix(google): raise on an empty candidate instead of a clean end_turn - #223
Open
gadievron wants to merge 1 commit into
Open
fix(google): raise on an empty candidate instead of a clean end_turn#223gadievron wants to merge 1 commit into
gadievron wants to merge 1 commit into
Conversation
gadievron
requested review from
dgeyshis,
shahar-davidson and
sounil
as code owners
August 8, 2026 08:30
The Gemini adapter guarded the no-candidates case (prompt blocked) but not a present candidate that carried no usable parts -- a thinking-only or blank candidate with a clean STOP finish. It returned CompletionResult(content=[], stop_reason="end_turn"), which the pipeline reads as a clean, passing result; for a security verifier an empty end_turn is a silent false-negative. Add the no-usable-content guard the sibling adapters already have -- the Anthropic adapter (R4-1), the OpenAI Responses path, and (via #208) the OpenAI chat path all raise LLMResponseError on empty content. Placed after the refusal check (the more specific signal) and before stop-reason mapping. A tool-use-only candidate stays valid (content_blocks is non-empty). Regression test: a present candidate with empty parts now raises LLMResponseError (was a clean end_turn); a function_call-only candidate still resolves as a valid tool_use. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
gadievron
force-pushed
the
fix/google-empty-content-silent-fn
branch
from
August 8, 2026 08:40
0e48273 to
17614fa
Compare
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.
Root cause
utilities/llm/providers/google.py::_response_to_unifiedguarded the no-candidates case (prompt blocked → raise, with a comment noting an emptyend_turn"would read as a clean (passing) result — for a security tool that would mask a refusal as a non-finding"). But it did not guard a present candidate that carried no usable parts — a thinking-only/blank candidate with a cleanSTOPfinish. That returnedCompletionResult(content=[], stop_reason="end_turn"), which the pipeline (and the finding-verifier) reads as a clean, passing result: a silent false-negative for a security tool.This is the same empty-content silent-FN closed for the OpenAI chat path in #208 and already guarded in the Anthropic adapter (R4-1) and the OpenAI Responses path — google was the remaining gap. Surfaced by an adversarial review of the repo_explorer resilience fix (#222).
Fix
Add the
if not content_blocks: raise LLMResponseError(...)guard after the refusal check (more specific signal first) and before stop-reason mapping, mirroring the siblings. A tool-use-only candidate (function_call part, no text) stays valid becausecontent_blocksis non-empty.Reproduction
A Gemini response with one candidate,
finish_reason="STOP",content.parts=[].Regression tests (
tests/test_llm_google_adapter.py)test_present_candidate_with_empty_parts_raises_not_clean_end_turn— RED before, GREEN after.test_tool_use_only_candidate_is_valid_not_empty— control: function-call-only stays valid.Compatibility
No API/signature change. Behavior change: an empty Gemini candidate now raises
LLMResponseErrorinstead of returning an emptyend_turn. Text and tool-use responses are unaffected; refusal/blocked candidates still raise first. Consistency fix — brings google in line with the other three provider paths.Known limitations (latent, not reachable in current config)
An adversarial sweep confirmed the guard raises only on genuinely-empty responses; two latent edges were verified unreachable today (OpenAnt requests a single, text-only candidate — no
candidate_count/response_modalities/code_executionconfig anywhere):inline_data/executable_code/code_execution_result) would be treated as empty and raise. Would need part-handling if image/code-exec output is ever enabled.candidates[0]is inspected; a multi-candidate response with an empty first candidate would raise. Not reachable whilecandidate_countdefaults to 1.The error message now names the thinking-model token-budget-exhaustion case (empty parts +
MAX_TOKENS) rather than only "filtered/malformed", matching the OpenAI Responses adapter's message.