Home / Function/ aformat_document() — langchain Function Reference

aformat_document() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  fb21269c_c5f5_be1c_b818_f16b08aab496["aformat_document()"]
  66049afc_0602_fbed_73fa_20a4904169e2["base.py"]
  fb21269c_c5f5_be1c_b818_f16b08aab496 -->|defined in| 66049afc_0602_fbed_73fa_20a4904169e2
  0295e9e8_9e6c_edee_9cdd_3bb377028854["aformat()"]
  fb21269c_c5f5_be1c_b818_f16b08aab496 -->|calls| 0295e9e8_9e6c_edee_9cdd_3bb377028854
  9d13d622_aa7b_65ce_8282_95208f051595["_get_document_info()"]
  fb21269c_c5f5_be1c_b818_f16b08aab496 -->|calls| 9d13d622_aa7b_65ce_8282_95208f051595
  style fb21269c_c5f5_be1c_b818_f16b08aab496 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/prompts/base.py lines 449–470

async def aformat_document(doc: Document, prompt: BasePromptTemplate[str]) -> str:
    """Async format a document into a string based on a prompt template.

    First, this pulls information from the document from two sources:

    1. `page_content`: This takes the information from the `document.page_content` and
        assigns it to a variable named `page_content`.
    2. `metadata`: This takes information from `document.metadata` and assigns it to
        variables of the same name.

    Those variables are then passed into the `prompt` to produce a formatted string.

    Args:
        doc: `Document`, the `page_content` and `metadata` will be used to create the
            final string.
        prompt: `BasePromptTemplate`, will be used to format the `page_content` and
            `metadata` into the final string.

    Returns:
        String of the document formatted.
    """
    return await prompt.aformat(**_get_document_info(doc, prompt))

Subdomains

Frequently Asked Questions

What does aformat_document() do?
aformat_document() is a function in the langchain codebase, defined in libs/core/langchain_core/prompts/base.py.
Where is aformat_document() defined?
aformat_document() is defined in libs/core/langchain_core/prompts/base.py at line 449.
What does aformat_document() call?
aformat_document() calls 2 function(s): _get_document_info, aformat.

Analyze Your Own Codebase

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

Try Supermodel Free