Home / Function/ prompt_length() — langchain Function Reference

prompt_length() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  e3620d09_9942_1b8f_e2f2_af51e668aa11["prompt_length()"]
  2f364d76_a69d_403d_0a63_04792fe626bb["BaseCombineDocumentsChain"]
  e3620d09_9942_1b8f_e2f2_af51e668aa11 -->|defined in| 2f364d76_a69d_403d_0a63_04792fe626bb
  style e3620d09_9942_1b8f_e2f2_af51e668aa11 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/combine_documents/base.py lines 80–97

    def prompt_length(self, docs: list[Document], **kwargs: Any) -> int | None:  # noqa: ARG002
        """Return the prompt length given the documents passed in.

        This can be used by a caller to determine whether passing in a list
        of documents would exceed a certain prompt length. This useful when
        trying to ensure that the size of a prompt remains below a certain
        context limit.

        Args:
            docs: a list of documents to use to calculate the total prompt length.
            **kwargs: additional parameters that may be needed to calculate the
                prompt length.

        Returns:
            Returns None if the method does not depend on the prompt length,
            otherwise the length of the prompt in tokens.
        """
        return None

Subdomains

Frequently Asked Questions

What does prompt_length() do?
prompt_length() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/combine_documents/base.py.
Where is prompt_length() defined?
prompt_length() is defined in libs/langchain/langchain_classic/chains/combine_documents/base.py at line 80.

Analyze Your Own Codebase

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

Try Supermodel Free