Skip to content

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
VANDRANKI:fix/extract-reasoning-ignore-empty-string
Closed

fix: ignore empty string reasoning_content in _extract_reasoning_from_additional_kwargs#36924
PRABHU KIRAN VANDRANKI (VANDRANKI) wants to merge 1 commit intolangchain-ai:masterfrom
VANDRANKI:fix/extract-reasoning-ignore-empty-string

Conversation

@VANDRANKI
Copy link
Copy Markdown

Fixes #36194.

Bug

_extract_reasoning_from_additional_kwargs uses reasoning_content is not None to detect a valid reasoning block. Some providers (e.g. Groq) emit "reasoning_content": "" in additional_kwargs even when no reasoning was produced. This caused an empty ReasoningContentBlock ({"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 None to a truthy check:

# Before
if reasoning_content is not None and isinstance(reasoning_content, str):

# After
if reasoning_content and isinstance(reasoning_content, str):

An empty string is falsy, so it is now skipped. A non-empty string still produces the reasoning block as before.

…_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>
@github-actions
Copy link
Copy Markdown

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:

  1. Comment on the linked issue to request assignment from a maintainer
  2. Once assigned, your PR will be reopened automatically

Maintainers: reopen this PR or remove the missing-issue-link label to bypass this check.

@github-actions github-actions Bot closed this Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core `langchain-core` package issues & PRs external fix For PRs that implement a fix missing-issue-link new-contributor size: XS < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_extract_reasoning_from_additional_kwargs should ignore empty strings

1 participant