Skip to content

Conversation

@Chesars
Copy link
Contributor

@Chesars Chesars commented Nov 28, 2025

Title

fix(gemini): use thought:true instead of thoughtSignature to detect thinking blocks

Relevant issues

Fixes the issue reported in #16854 (comment)

Pre-Submission checklist

  • I have Added testing in the tests/litellm/ directory
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🐛 Bug Fix

Changes

The previous implementation of _extract_thinking_blocks_from_parts incorrectly used "thoughtSignature" in part as the criterion to detect thinking blocks.

Per Google's docs:

  • thought: true indicates that a part contains reasoning/thinking content
  • thoughtSignature is just a token for multi-turn context preservation (docs)

A part can have thoughtSignature without thought: true (e.g., function calls), which caused functionCall data to leak into reasoning_content when using Gemini 2.5 Pro with streaming + tools.

Before:
content: "Hello! How can I help you today?"
reasoning_content: { text: "Hello! How can I help you today?" } // duplicated!

After:
content: "Hello! How can I help you today?"
reasoning_content: None // correct - only shows reasoning when thought: true

Changes:

  • _extract_thinking_blocks_from_parts checks part.get("thought") is True`
  • Extracts actual text content instead of json.dumps(part)
  • Includes signature (optional in Gemini 2.5)

…hinking blocks

The previous implementation incorrectly used `thoughtSignature` as the criterion
to detect thinking blocks. However, per Google's docs:
- `thought: true` indicates that a part contains reasoning/thinking content
- `thoughtSignature` is just a token for multi-turn context preservation
  (a part can have thoughtSignature without thought:true, e.g., function calls)

This caused functionCall data to leak into reasoning_content when using
Gemini 2.5 Pro with streaming + tools enabled.

Changes:
- _extract_thinking_blocks_from_parts now checks `part.get("thought") is True`
- Extract actual text content instead of json.dumps(part)
- Include signature only when present (optional in Gemini 2.5)

Refs:
- https://ai.google.dev/gemini-api/docs/thinking
- https://ai.google.dev/gemini-api/docs/thought-signatures
@vercel
Copy link

vercel bot commented Nov 28, 2025

@Chesars is attempting to deploy a commit to the CLERKIEAI Team on Vercel.

A member of the Team first needs to authorize it.

@Chesars Chesars changed the title fix(gemini): use thought:true instead of thoughtSignature to detect t… fix(gemini): fix reasoning_content showing duplicate content in streaming responses Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant