LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • MCP Adapters
    • Overview
    • Agents
    • Callbacks
    • Chains
    • Chat models
    • Embeddings
    • Evaluation
    • Globals
    • Hub
    • Memory
    • Output parsers
    • Retrievers
    • Runnables
    • LangSmith
    • Storage
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    MCP Adapters
    OverviewAgentsCallbacksChainsChat modelsEmbeddingsEvaluationGlobalsHubMemoryOutput parsersRetrieversRunnablesLangSmithStorage
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-classicchainscombine_documentsbaseBaseCombineDocumentsChainprompt_length
    Method●Since v1.0

    prompt_length

    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.

    Copy
    prompt_length(
      self,
      docs: list[Document],
      **kwargs: Any = {}
    ) -> int | None

    Parameters

    NameTypeDescription
    docs*list[Document]

    a list of documents to use to calculate the total prompt length.

    **kwargsAny
    Default:{}

    additional parameters that may be needed to calculate the prompt length.

    View source on GitHub