Skip to content

fix: set include_thoughts=False when thinking_budget is 0#2853

Merged
julian-risch merged 13 commits intodeepset-ai:mainfrom
yaowubarbara:fix/google-genai-thinking-budget-zero
Feb 27, 2026
Merged

fix: set include_thoughts=False when thinking_budget is 0#2853
julian-risch merged 13 commits intodeepset-ai:mainfrom
yaowubarbara:fix/google-genai-thinking-budget-zero

Conversation

@yaowubarbara
Copy link
Copy Markdown
Contributor

Related Issues

Fixes #2845

Proposed Changes

When thinking_budget is set to 0 (to disable thinking), the include_thoughts parameter in ThinkingConfig was hardcoded to True. This caused Vertex AI to reject the request with a 400 INVALID_ARGUMENT error because you can't request thinking output when thinking is disabled.

The fix sets include_thoughts based on whether thinking is actually enabled (thinking_budget != 0).

How did you test it?

Updated the existing test_process_thinking_budget test to verify include_thoughts is correct for each scenario:

  • thinking_budget=1024 -> include_thoughts=True
  • thinking_budget=-1 (dynamic) -> include_thoughts=True
  • thinking_budget=0 (disabled) -> include_thoughts=False
  • thinking_budget=24576 -> include_thoughts=True

All existing tests still pass.

Checklist

  • I have read the contributors guidelines and the code of conduct
  • I have updated the related issue with new insights and changes
  • I added unit tests and updated the docstrings
  • I used one of the conventional commit types for my PR title

@yaowubarbara yaowubarbara requested a review from a team as a code owner February 18, 2026 03:31
@yaowubarbara yaowubarbara requested review from julian-risch and removed request for a team February 18, 2026 03:31
@julian-risch
Copy link
Copy Markdown
Member

Hi @yaowubarbara Thank you for opening this pull request and also for creating the corresponding issue. It seems that your commit 103ca1a addresses the issue in the Google Gen AI integration but there are also other changes in the PR that change the Anthropic integration. Could you please create a separate PR for any changes to this other integration?

@julian-risch
Copy link
Copy Markdown
Member

Ah, I just saw your other PR that already got merged: #2849
So could you please remove those changes from this open PR here? Thank you!

@fkdosilovic
Copy link
Copy Markdown

My two cents to the PR:

  1. I believe that the most sensible option would be to allow for setting the include_thoughts in generation_kwargs explicitly by the user. Only boolean values should be allowed! If no value for include_thoughts is set, then the value should be set accordingly, taking into account the thinking_budget or thinking_level arguments.
  2. The include_thoughts should be changed both for thinking_budget and thinking_level branches. The need for these two branches is due to the fact that Gemini 2.5 and Gemini 3 have different parameters for controlling thinking/reasoning effort of the models.

General logic for setting include_thoughts if thinking_budget or thinking_level is not set:

# for thinking_budget branch. this is added after the basic type validation of thinking_budget
include_thoughts = generation_kwargs.get('include_thoughts', None)
if include_thoughts is None:
    if thinking_budget == 0:
        include_thoughts = False:
    else:
        include_thoughts = True
        
# for thinking_level branch.  this is added after the basic validation of thinking_level
include_thoughts = generation_kwargs.get('include_thoughts', None)
if include_thoughts is None:
    if thinking_level == types.ThinkingLevel.THINKING_LEVEL_MINIMAL:
        include_thoughts = False:
    else:
        include_thoughts = True

Of course, @yaowubarbara, don't make any changes until core maintainers comment on my aforementioned suggestions.

When thinking_budget is set to 0 (disabling thinking), include_thoughts
was hardcoded to True, causing a 400 INVALID_ARGUMENT error from the
Vertex AI API. Now include_thoughts is set based on whether thinking
is actually enabled (thinking_budget != 0).

Closes deepset-ai/haystack#2845
@yaowubarbara yaowubarbara force-pushed the fix/google-genai-thinking-budget-zero branch from 103ca1a to f45f584 Compare February 19, 2026 01:54
@yaowubarbara
Copy link
Copy Markdown
Contributor Author

Thanks for pointing that out! I've removed the Anthropic changes from this PR, now it only contains the Google GenAI fix commit. Those changes was already merged in #2849, sorry about the mix-up.

@yaowubarbara
Copy link
Copy Markdown
Contributor Author

Thanks for the detailed suggestions @fkdosilovic! That makes alot of sense to allow users to explicitly set include_thoughts via generation_kwargs, and handling both thinking_budget and thinking_level branches separately. I'll hold off on making changes until the core maintainers weigh in on this approach.

@anakin87
Copy link
Copy Markdown
Member

Related PR by @tstadel: #2737

@fkdosilovic
Copy link
Copy Markdown

Related PR by @tstadel: #2737

It seems to be a PR that added the thinking_level support, but it does not mention the subtle bug and edge case related to this PR.

Copy link
Copy Markdown
Member

@julian-risch julian-risch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening this PR!
I agree with @fkdosilovic 's suggestion shared in the comment above.
@yaowubarbara Could you please adjust the PR so that it works with series 3 models that use thinking_level and with series 2.5 models that use thinking_budget? In particular, if no value for include_thoughts is set by the user, then the value should be set automatically based on thinking_budget or thinking_level.

…evel

- Allow users to explicitly set include_thoughts via generation_kwargs,
  overriding the auto-derived value for both thinking_budget and
  thinking_level branches.
- Auto-derive include_thoughts=False when thinking_level is MINIMAL,
  matching the existing behavior for thinking_budget=0.
- Pop include_thoughts from generation_kwargs to prevent it leaking as
  an unknown kwarg to GenerateContentConfig.
- Add include_thoughts assertions to thinking_level tests and new tests
  for explicit user overrides.
@yaowubarbara
Copy link
Copy Markdown
Contributor Author

Hi @julian-risch @fkdosilovic, pushed the updates:

  • Auto-derive include_thoughts for thinking_level branch (MINIMAL → False, others → True)
  • Support explicit include_thoughts override via generation_kwargs in both branches
  • Added tests for all cases

All passing locally. Ready for another look!

@julian-risch julian-risch self-requested a review February 25, 2026 09:18
Comment thread integrations/google_genai/tests/test_chat_generator.py Outdated
Copy link
Copy Markdown
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@julian-risch julian-risch merged commit 797ddfc into deepset-ai:main Feb 27, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Google GenAI - Bug in GoogleGenAIChatGenerator when thinking budget is set to 0

4 participants