Skip to content

fix(core): fix setting ChatGeneration.text#35191

Merged
ccurme (ccurme) merged 2 commits into
masterfrom
cc/fix_chat_generation_text
Feb 12, 2026
Merged

fix(core): fix setting ChatGeneration.text#35191
ccurme (ccurme) merged 2 commits into
masterfrom
cc/fix_chat_generation_text

Conversation

@ccurme
Copy link
Copy Markdown
Collaborator

We previously had a hack where we'd take the first text block.

This isn't suited to model calls nowadays, where we generally expect multiple text blocks in a single invocation. For example when using Opus 4.6 with adaptive thinking, we can get output of the form:

[
  {
    "text": "\n\n",
    "type": "text"
  },
  {
    "signature": "...",
    "thinking": 'The user said "Hello"...',
    "type": "thinking"
  },
  {
    "text": '{"response":"Hello! How can I help you today?"}',
    "type": "text"
  }
]

(Note: I verified that the raw response from Anthropic in the above case genuinely contains TextBlock(citations=None, text='\n\n', type='text') as the first content element.)

This was mentioned in a comment here.

The impact here is that output parsers do not access the full text content, only the first block. So structured output can fail.

@github-actions github-actions Bot added internal core `langchain-core` package issues & PRs fix For PRs that implement a fix and removed internal labels Feb 12, 2026
@mdrxy Mason Daugherty (mdrxy) changed the title fix(core): fix setting ChatGeneration.text fix(core): fix setting ChatGeneration.text Feb 12, 2026
@github-actions github-actions Bot added fix For PRs that implement a fix and removed fix For PRs that implement a fix labels Feb 12, 2026
Copy link
Copy Markdown
Member

@mdrxy Mason Daugherty (mdrxy) left a comment

Choose a reason for hiding this comment

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

the old code accepted dict blocks without a type key

the message.text property requires block.get("type") == "text" explicitly, so blocks missing a type key are now excluded

is this a problem?

@ccurme ccurme (ccurme) merged commit 16cabfa into master Feb 12, 2026
88 of 90 checks passed
@ccurme ccurme (ccurme) deleted the cc/fix_chat_generation_text branch February 12, 2026 20:43
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 fix For PRs that implement a fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants