Repository navigation
Insights: read AIMessage.text as the property it is - #54
Merged
Merged
Conversation
The unpacker's callable() fallback for older LangChain walked into the str subclass the property now returns, which answers a call with a deprecation warning on every run. Read the property; fall back to content.
| # so a callable() check here would walk straight into that | ||
| text = getattr(m, "text", None) | ||
| if not isinstance(text, str): | ||
| text = m.content if isinstance(m.content, str) else "" |
There was a problem hiding this comment.
nit: Call text() when m.text is callable but not a str (not blocking).
The fallback runs only on an older langchain-core, where text is a plain method. On that version, Anthropic replies carry content as a list of blocks. The old text() call extracted the text from those blocks. This fallback returns "" for a list, so the answer is lost.
Suggested change
| text = m.content if isinstance(m.content, str) else "" | |
| text = text() if callable(text) else (m.content if isinstance(m.content, str) else "") |
The isinstance(text, str) check already catches the new str subclass first, so the deprecation warning cannot fire here. The Dockerfile does not pin langchain, so this path is rare in production.
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.
The transcript unpacker called
.text()through acallable()fallback meant for older LangChain. The property now returns a str subclass that still answers a call, with a deprecation warning on every run. Read the property and fall back tocontent. Verified with warnings turned into errors.