Skip to content

Conversation

olieydt
Copy link

@olieydt olieydt commented Sep 5, 2025

  • Description: BaseMessage .text() filters for blocks of type "text" when content is a list of dict. Concatenated messages can result in type != "text" but containing a text prop. This results in calling .text() on the message but receiving "". To address this, only consider if a text prop is present and a str.

BaseMessage .text() filters for type "text" when content is a list of dict. Concatenated messages can result in type != "text" but containing a text prop. This results in calling .text() on the message but receiving "".

If a text prop is present, include it.
@olieydt olieydt requested a review from eyurtsev as a code owner September 5, 2025 14:18
Copy link

vercel bot commented Sep 5, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
langchain Ignored Ignored Preview Sep 5, 2025 2:23pm

Copy link

codspeed-hq bot commented Sep 5, 2025

CodSpeed WallTime Performance Report

Merging #32829 will not alter performance

Comparing olieydt:patch-1 (d972ca3) with master (bc91a48)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 13 untouched benchmarks

@olieydt olieydt marked this pull request as draft September 5, 2025 14:25
Copy link

codspeed-hq bot commented Sep 5, 2025

CodSpeed Instrumentation Performance Report

Merging #32829 will not alter performance

Comparing olieydt:patch-1 (d972ca3) with master (bc91a48)

Summary

✅ 14 untouched benchmarks

@mdrxy mdrxy changed the title fix(core): fix BaseMessage .text() filtering out blocks with text fix(core): fix BaseMessage .text() filtering out blocks with text Sep 5, 2025
@mdrxy mdrxy added the core Related to the package `langchain-core` label Sep 5, 2025
@mdrxy
Copy link
Collaborator

mdrxy commented Sep 5, 2025

You may want to take a look at the new implementations in our wip-v1.0 branch - this will soon be outdated/may no longer be needed

Copy link
Collaborator

@ccurme ccurme left a comment

Choose a reason for hiding this comment

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

@olieydt can you say more about the context for this? What models are returning blocks with "text" keys that are not "type": "text"?

I think semantically it makes sense for .text() to only filter to blocks matching a certain type. It's easy to imagine situations where this is desirable:

[
    {"type": "internal_thought_process": "text": "<LLM inner thoughts...>"},
    {"type": "text", "text": "Here is the answer..."},
]

^ in that example we'd likely just want .text() to return the output message text.

@ccurme
Copy link
Collaborator

ccurme commented Sep 11, 2025

Closing for now— the failing tests here indicate that this is deliberate behavior. I'd suggest opening an issue and giving additional context so we can design a proper solution (potentially as part of langchain 1.0).

@ccurme ccurme closed this Sep 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to the package `langchain-core`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants