Home / Function/ __str__() — langchain Function Reference

__str__() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  91725c65_30e1_404e_e7f5_2af3bf928b1e["__str__()"]
  935e1032_d88a_f226_7789_5aacc43bb0c8["Document"]
  91725c65_30e1_404e_e7f5_2af3bf928b1e -->|defined in| 935e1032_d88a_f226_7789_5aacc43bb0c8
  style 91725c65_30e1_404e_e7f5_2af3bf928b1e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/documents/base.py lines 331–347

    def __str__(self) -> str:
        """Override `__str__` to restrict it to page_content and metadata.

        Returns:
            A string representation of the `Document`.
        """
        # The format matches pydantic format for __str__.
        #
        # The purpose of this change is to make sure that user code that feeds
        # Document objects directly into prompts remains unchanged due to the addition
        # of the id field (or any other fields in the future).
        #
        # This override will likely be removed in the future in favor of a more general
        # solution of formatting content directly inside the prompts.
        if self.metadata:
            return f"page_content='{self.page_content}' metadata={self.metadata}"
        return f"page_content='{self.page_content}'"

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free