text() — langchain Function Reference
Architecture documentation for the text() function in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 100b1f91_cae4_8f2d_9794_0b9d1badef48["text()"] abb7c122_ee7b_4c8f_ffaa_3d3d63c4fab7["BaseMessage"] 100b1f91_cae4_8f2d_9794_0b9d1badef48 -->|defined in| abb7c122_ee7b_4c8f_ffaa_3d3d63c4fab7 3e884c1e_b5b9_62f5_9953_83e5f43a0de9["__call__()"] 3e884c1e_b5b9_62f5_9953_83e5f43a0de9 -->|calls| 100b1f91_cae4_8f2d_9794_0b9d1badef48 style 100b1f91_cae4_8f2d_9794_0b9d1badef48 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/messages/base.py lines 263–292
def text(self) -> TextAccessor:
"""Get the text content of the message as a string.
Can be used as both property (`message.text`) and method (`message.text()`).
Handles both string and list content types (e.g. for content blocks). Only
extracts blocks with `type: 'text'`; other block types are ignored.
!!! deprecated
As of `langchain-core` 1.0.0, calling `.text()` as a method is deprecated.
Use `.text` as a property instead. This method will be removed in 2.0.0.
Returns:
The text content of the message.
"""
if isinstance(self.content, str):
text_value = self.content
else:
# Must be a list
blocks = [
block
for block in self.content
if isinstance(block, str)
or (block.get("type") == "text" and isinstance(block.get("text"), str))
]
text_value = "".join(
block if isinstance(block, str) else block["text"] for block in blocks
)
return TextAccessor(text_value)
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does text() do?
text() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/base.py.
Where is text() defined?
text() is defined in libs/core/langchain_core/messages/base.py at line 263.
What calls text()?
text() is called by 1 function(s): __call__.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free