Home / Function/ as_string() — langchain Function Reference

as_string() — langchain Function Reference

Architecture documentation for the as_string() function in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  7bcae93a_806d_7517_0417_b3d6b2e74ec9["as_string()"]
  3557cb87_7ae6_78b3_0aa2_bbb7f023fdce["Blob"]
  7bcae93a_806d_7517_0417_b3d6b2e74ec9 -->|defined in| 3557cb87_7ae6_78b3_0aa2_bbb7f023fdce
  style 7bcae93a_806d_7517_0417_b3d6b2e74ec9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/documents/base.py lines 158–174

    def as_string(self) -> str:
        """Read data as a string.

        Raises:
            ValueError: If the blob cannot be represented as a string.

        Returns:
            The data as a string.
        """
        if self.data is None and self.path:
            return Path(self.path).read_text(encoding=self.encoding)
        if isinstance(self.data, bytes):
            return self.data.decode(self.encoding)
        if isinstance(self.data, str):
            return self.data
        msg = f"Unable to get string for blob {self}"
        raise ValueError(msg)

Subdomains

Frequently Asked Questions

What does as_string() do?
as_string() is a function in the langchain codebase, defined in libs/core/langchain_core/documents/base.py.
Where is as_string() defined?
as_string() is defined in libs/core/langchain_core/documents/base.py at line 158.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free