From fa3159b6e847518ef225086cc7f52babb2ac5aaa Mon Sep 17 00:00:00 2001 From: bahtya Date: Thu, 9 Apr 2026 00:33:18 +0800 Subject: [PATCH] fix(gemini): capture thoughtSignature from sibling thought parts Gemini may place thoughtSignature on a separate thought part (thought: true) rather than the functionCall part. _transform_parts only checked the functionCall part for thoughtSignature, so the signature was lost when it was on a sibling thought part. Now we collect all thoughtSignature values from all parts before iterating, and fall back to the first available signature when a functionCall part has none of its own. Fixes #25322 (Failure 1) Signed-off-by: bahtya --- .../gemini/vertex_and_google_ai_studio_gemini.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py index a90e05919fb..3088da30994 100644 --- a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py +++ b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py @@ -1585,6 +1585,13 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig): ]: function: Optional[ChatCompletionToolCallFunctionChunk] = None _tools: List[ChatCompletionToolCallChunk] = [] + # Collect all thoughtSignature values from any part (Gemini may place + # the signature on a separate thought part, not the functionCall part) + _all_signatures = [ + p.get("thoughtSignature") + for p in parts + if p.get("thoughtSignature") + ] for part in parts: if "functionCall" in part: _function_chunk: ChatCompletionToolCallFunctionChunk = { @@ -1593,8 +1600,11 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig): part["functionCall"]["args"], ensure_ascii=False ), } - # Extract thought signature if present - thought_signature = part.get("thoughtSignature") + # Extract thought signature: prefer this part's own, fallback to + # a signature from a sibling thought part + thought_signature = part.get("thoughtSignature") or ( + _all_signatures[0] if _all_signatures else None + ) if is_function_call is True: function_dict: Dict[str, Any] = dict(_function_chunk)