Skip to content

fix(gemini): trailing empty text part with thoughtSignature#757

Open
o0O96O0o wants to merge 6 commits into
cloudwego:mainfrom
o0O96O0o:fix(gemini)/trailing-thoughtSignature
Open

fix(gemini): trailing empty text part with thoughtSignature#757
o0O96O0o wants to merge 6 commits into
cloudwego:mainfrom
o0O96O0o:fix(gemini)/trailing-thoughtSignature

Conversation

@o0O96O0o

@o0O96O0o o0O96O0o commented Apr 1, 2026

Copy link
Copy Markdown

What type of PR is this?

fix: there is trailing empty text candidate part with thoughtSignature instead of placing the signature in the first part of functionCall (as described in the document https://docs.cloud.google.com/vertex-ai/generative-ai/docs/thought-signatures)

Check the PR title.

  • fix(gemini): trailing empty text part with thoughtSignature

(Optional) Translate the PR title into Chinese.

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
fix: there is trailing empty text candidate part with thoughtSignature instead of placing the signature in the first part of functionCall (as described in the document https://docs.cloud.google.com/vertex-ai/generative-ai/docs/thought-signatures) like:

"candidates": [
            {
                "content": {
                    "parts": [
                        {
                            "functionCall": {
                                ...
                            }
                        },
                        {
                            "text": "",
                            "thoughtSignature": "...thoughtSignature here..."
                        }
                    ],
                    "role": "model"
                },
                "finishReason": "STOP",
                "groundingMetadata": {
                    "retrievalMetadata": {},
                    "searchEntryPoint": {
                        "renderedContent": "..."
                    },
                    "webSearchQueries": [
                        ...
                    ]
                }
            }
        ],

added fallback handle to move the thoughtSignature in the empty part to the first tool_call part

zh(optional):

(Optional) Which issue(s) this PR fixes:

fixed: #756

(optional) The PR that updates user documentation:

@CLAassistant

CLAassistant commented Apr 1, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ tangchaojun-bytedance
✅ o0O96O0o
❌ hehuaisen


hehuaisen seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@tangchaojun-bytedance

Copy link
Copy Markdown
Collaborator

CLA assistant check Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

hehuaisen seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@o0O96O0o hello, please sign the CLA.

@tangchaojun-bytedance

Copy link
Copy Markdown
Collaborator

@o0O96O0o The fix direction makes sense and it covers the reported Gemini response shape. My only concern is that the fallback is currently too broad: it moves a thoughtSignature from any non-functionCall part after a functionCall, not only from the trailing empty text/signature-only part described in the issue.

Could we restrict the fallback to that exact empty-part case and add a negative test where a real non-empty output part with thoughtSignature should keep its signature instead of copying it to the tool call?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Function call is missing a thought_signature in functionCall parts from Gemini API (model: gemini-3-flash-preview)

3 participants