Skip to content

Gemini returns THOUGHT: content in text parts without part.thought=True #2121

Closed as not planned

Description

@itaihochman-cesura

Summary

When using Gemini 2.5 Flash with ThinkingConfig (include_thoughts=True or omitted), thought/reasoning content sometimes appears in the regular text field of response parts with a "THOUGHT:" prefix, but no part has part.thought=True. All parts have thought: null and has_thought_signature: false.

Per the Gemini thinking docs, thought content should be returned as separate parts with the thought boolean set to true. Instead, it arrives as literal text in normal text parts.

Environment

  • Package: google-genai 1.64.0 (also observed with 1.57.0)
  • Model: gemini-2.5-flash
  • Backend: Vertex AI (me-west1, global)
  • Mode: Streaming (generate_content_stream)
  • Python: 3.11

Steps to Reproduce

  1. Configure ThinkingConfig with thinking_budget=128 (or similar) for gemini-2.5-flash
  2. Call client.aio.models.generate_content_stream() with a prompt that triggers reasoning
  3. Iterate over streamed chunks and inspect chunk.candidates[0].content.parts
  4. Observe: thought content appears in part.text with "THOUGHT:" prefix, but part.thought is None for all parts

Expected Behavior

  • Thought content should be in parts with part.thought=True
  • Client code can filter by getattr(part, "thought", False) to separate thoughts from answer text

Actual Behavior

  • Thought content appears in part.text with "THOUGHT:" prefix
  • All parts have part.thought is None and part.thought_signature is None
  • Part-level filtering (if part.thought: continue) never triggers
  • We must use text-level filtering (strip THOUGHT: blocks) as a workaround

Diagnostic Data (from production log)

{
  "event": "gemini_thought_leak_diagnostic",
  "model": "gemini-2.5-flash",
  "vertex_region": "global",
  "raw_response": "THOUGHT: The user chose option 2 for character dynamics...\n\n[actual response text]",
  "removed_blocks_count": 1,
  "total_chars_removed": 243,
  "thought_parts_filtered": 0,
  "chunks_metadata": [
    {"parts": [{"thought": null, "has_thought_signature": false, "text_length": 2}], "thought_parts_filtered": 0},
    {"parts": [{"thought": null, "has_thought_signature": false, "text_length": 77}], "thought_parts_filtered": 0}
  ]
}

Key observation: thought_parts_filtered: 0 — no parts were marked as thought by the API, yet we had to remove a 243-char THOUGHT: block from the text.

Workaround (not effective)

We tried to strips THOUGHT: blocks from the concatenated text stream when they appear at block boundaries but it was not working. Also resending was not helping nor changing params like temperture

Question

Is this a known API/streaming behavior? Should thought content ever appear in part.text without part.thought=True? If so, is there a recommended way to detect and filter it at the SDK level?

Activity

  1. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Mar 5, 2026
  2. Venkaiahbabuneelam commented on Mar 12, 2026

    @Venkaiahbabuneelam

    Hey @itaihochman-cesura , Thanks for reaching out us!

    I tried the code shared by you and did not observe any error. Please find the +gist

    Thanks

  3. msnidal commented on Mar 13, 2026

    @msnidal

    Have been experiencing similar issues on gemini 3.1 flash lite preview, where the thought parts of the response were not being flagged with the thought bool flag and the response chunk .text property was therefore unable to distinguish them from the normal parts of the response. It's still unclear to me whether this is an API, model, or an SDK issue tbh.

    I am finding setting include_thoughts=False on the thinking config appears to be effectively solving this though, and I'm still receiving the thought signatures as well which is nice. - After some testing, the only consistent way I found to solve the issue was doing a structured output into a wrapped pydnatic structure with a reasoning and text field.

    If you truly need the thought text summaries I would recommend just wrapping your response in a structured output and including a thought property there instead for the time being.

  4. itaihochman-cesura commented on Mar 15, 2026

    @itaihochman-cesura
    Author

    It happens to me quite q lot in unpredictable way - it is hard to reproduce but it keeps happening on several models including gemini 3.1 flash, gemini 2.5 flash and gemini 2.5 pro (didnt check on 3.1 pro yet).
    Wrapping is a good idea but it looks that there is a real bug somewhere.
    BTW, happens with both include_thoughts=False and include_thoughts=True

  5. Venkaiahbabuneelam commented on Mar 18, 2026

    @Venkaiahbabuneelam

    Any update on my comment.?

  6. ChiragAga401 commented on Mar 18, 2026

    @ChiragAga401

    I am also experiencing this This does not happen every time so it is hard to check but sometimes even when told not to include any reasoning or thoughts it will still do so

  7. itaihochman-cesura commented on Mar 18, 2026

    @itaihochman-cesura
    Author

    @Venkaiahbabuneelam - I can't open the gist... can you give me access?

  8. github-actions commented on Mar 26, 2026

    @github-actions

    This issue has been marked as stale because it has been open for 7 days with no activity. It will be closed in 2 days if no further activity occurs.

  9. arnaud-secondlayer commented on Mar 30, 2026

    @arnaud-secondlayer

    Same here, this is not systematic but not difficult to reproduce either.
    Using gemini-2.5-flash with a thinking config

    ThinkingConfig(
        include_thoughts=True,
        thinking_budget=1024
    )
    
  10. Venkaiahbabuneelam commented on Mar 31, 2026

    @Venkaiahbabuneelam

    Hi @itaihochman-cesura,
    I have provided access to the Gist, please check and confirm.

    Thansk

  11. 6 remaining items

  12. Venkaiahbabuneelam commented on Apr 15, 2026

    @Venkaiahbabuneelam

    Hi @arnaud-secondlayer,

    Could you please try the latest version of genai? In my environment, we are currently using (>=1.68.0).

    Thanks

  13. github-actions commented on Apr 23, 2026

    @github-actions

    This issue has been marked as stale because it has been open for 7 days with no activity. It will be closed in 2 days if no further activity occurs.

  14. arnaud-secondlayer commented on Apr 23, 2026

    @arnaud-secondlayer

    I looks OK for me now

  15. Venkaiahbabuneelam commented on Apr 24, 2026

    @Venkaiahbabuneelam

    Thanks for your confirmation @arnaud-secondlayer.

  16. github-actions commented on May 2, 2026

    @github-actions

    This issue has been marked as stale because it has been open for 7 days with no activity. It will be closed in 2 days if no further activity occurs.

  17. github-actions commented on May 4, 2026

    @github-actions

    This issue was closed because it has been inactive for 9 days. Please post a new issue if you need further assistance. Thanks!

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

Metadata

Metadata

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.status:awaiting user responsestatus:staletype: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions