fix: ignore empty string reasoning_content in _extract_reasoning_from_additional_kwargs#36924
Closed
PRABHU KIRAN VANDRANKI (VANDRANKI) wants to merge 1 commit intolangchain-ai:masterfrom
Conversation
…_additional_kwargs Some providers (e.g. Groq) include "reasoning_content": "" in additional_kwargs even when no reasoning was produced. The previous check `reasoning_content is not None` treated an empty string as valid, inserting an empty ReasoningContentBlock into the message content list. Change to a truthy check so empty strings are skipped. Fixes langchain-ai#36194 Co-Authored-By: hlwz5735 <12751178+hlwz5735@users.noreply.github.com>
|
This PR has been automatically closed because you are not assigned to the linked issue. External contributors must be assigned to an issue before opening a PR for it. Please:
Maintainers: reopen this PR or remove the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #36194.
Bug
_extract_reasoning_from_additional_kwargsusesreasoning_content is not Noneto detect a valid reasoning block. Some providers (e.g. Groq) emit"reasoning_content": ""inadditional_kwargseven when no reasoning was produced. This caused an emptyReasoningContentBlock({"type": "reasoning", "reasoning": ""}) to be prepended to the message content list, which some downstream consumers treat as an error.Fix
Change the guard from
is not Noneto a truthy check:An empty string is falsy, so it is now skipped. A non-empty string still produces the reasoning block as before.