Home / Function/ _load_template() — langchain Function Reference

_load_template() — langchain Function Reference

Architecture documentation for the _load_template() function in loading.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  9097629d_a2b8_9c6b_7aad_8779e19c2517["_load_template()"]
  968242b5_edb4_6604_0d16_e821da9180f5["loading.py"]
  9097629d_a2b8_9c6b_7aad_8779e19c2517 -->|defined in| 968242b5_edb4_6604_0d16_e821da9180f5
  a95ffdb2_1800_1638_7e16_d0060630d74c["_load_few_shot_prompt()"]
  a95ffdb2_1800_1638_7e16_d0060630d74c -->|calls| 9097629d_a2b8_9c6b_7aad_8779e19c2517
  0114f8ef_ddea_b4b5_1241_647023b433a8["_load_prompt()"]
  0114f8ef_ddea_b4b5_1241_647023b433a8 -->|calls| 9097629d_a2b8_9c6b_7aad_8779e19c2517
  style 9097629d_a2b8_9c6b_7aad_8779e19c2517 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/prompts/loading.py lines 44–61

def _load_template(var_name: str, config: dict) -> dict:
    """Load template from the path if applicable."""
    # Check if template_path exists in config.
    if f"{var_name}_path" in config:
        # If it does, make sure template variable doesn't also exist.
        if var_name in config:
            msg = f"Both `{var_name}_path` and `{var_name}` cannot be provided."
            raise ValueError(msg)
        # Pop the template path from the config.
        template_path = Path(config.pop(f"{var_name}_path"))
        # Load the template.
        if template_path.suffix == ".txt":
            template = template_path.read_text(encoding="utf-8")
        else:
            raise ValueError
        # Set the template variable to the extracted variable.
        config[var_name] = template
    return config

Subdomains

Frequently Asked Questions

What does _load_template() do?
_load_template() is a function in the langchain codebase, defined in libs/core/langchain_core/prompts/loading.py.
Where is _load_template() defined?
_load_template() is defined in libs/core/langchain_core/prompts/loading.py at line 44.
What calls _load_template()?
_load_template() is called by 2 function(s): _load_few_shot_prompt, _load_prompt.

Analyze Your Own Codebase

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

Try Supermodel Free