TextAccessor Class — langchain Architecture
Architecture documentation for the TextAccessor class in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 40fd239f_3781_2e6b_a3c2_9acf51b31b16["TextAccessor"] 323271a6_dbeb_1ac5_e224_a66bfb56191b["base.py"] 40fd239f_3781_2e6b_a3c2_9acf51b31b16 -->|defined in| 323271a6_dbeb_1ac5_e224_a66bfb56191b 95b14523_aea9_c992_5247_fe795f9a0989["__new__()"] 40fd239f_3781_2e6b_a3c2_9acf51b31b16 -->|method| 95b14523_aea9_c992_5247_fe795f9a0989 ed262a79_fa2f_abac_9c4f_b3583e725c76["__call__()"] 40fd239f_3781_2e6b_a3c2_9acf51b31b16 -->|method| ed262a79_fa2f_abac_9c4f_b3583e725c76
Relationship Graph
Source Code
libs/core/langchain_core/messages/base.py lines 47–90
class TextAccessor(str):
"""String-like object that supports both property and method access patterns.
Exists to maintain backward compatibility while transitioning from method-based to
property-based text access in message objects. In LangChain <v1.0, message text was
accessed via `.text()` method calls. In v1.0=<, the preferred pattern is property
access via `.text`.
Rather than breaking existing code immediately, `TextAccessor` allows both
patterns:
- Modern property access: `message.text` (returns string directly)
- Legacy method access: `message.text()` (callable, emits deprecation warning)
"""
__slots__ = ()
def __new__(cls, value: str) -> Self:
"""Create new TextAccessor instance."""
return str.__new__(cls, value)
def __call__(self) -> str:
"""Enable method-style text access for backward compatibility.
This method exists solely to support legacy code that calls `.text()`
as a method. New code should use property access (`.text`) instead.
!!! 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 string content, identical to property access.
"""
warn_deprecated(
since="1.0.0",
message=(
"Calling .text() as a method is deprecated. "
"Use .text as a property instead (e.g., message.text)."
),
removal="2.0.0",
)
return str(self)
Defined In
Source
Frequently Asked Questions
What is the TextAccessor class?
TextAccessor is a class in the langchain codebase, defined in libs/core/langchain_core/messages/base.py.
Where is TextAccessor defined?
TextAccessor is defined in libs/core/langchain_core/messages/base.py at line 47.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free