Home / Function/ _get_document_info() — langchain Function Reference

_get_document_info() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/core/langchain_core/prompts/base.py lines 396–411

def _get_document_info(doc: Document, prompt: BasePromptTemplate[str]) -> dict:
    base_info = {"page_content": doc.page_content, **doc.metadata}
    missing_metadata = set(prompt.input_variables).difference(base_info)
    if len(missing_metadata) > 0:
        required_metadata = [
            iv for iv in prompt.input_variables if iv != "page_content"
        ]
        msg = (
            f"Document prompt requires documents to have metadata variables: "
            f"{required_metadata}. Received document with missing metadata: "
            f"{list(missing_metadata)}."
        )
        raise ValueError(
            create_message(message=msg, error_code=ErrorCode.INVALID_PROMPT_INPUT)
        )
    return {k: base_info[k] for k in prompt.input_variables}

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free