base.py — langchain Source File
Architecture documentation for base.py, a python file in the langchain codebase. 19 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 66049afc_0602_fbed_73fa_20a4904169e2["base.py"] 96729794_9892_052d_0786_aad18ffd341b["builtins"] 66049afc_0602_fbed_73fa_20a4904169e2 --> 96729794_9892_052d_0786_aad18ffd341b 69e1d8cc_6173_dcd0_bfdf_2132d8e1ce56["contextlib"] 66049afc_0602_fbed_73fa_20a4904169e2 --> 69e1d8cc_6173_dcd0_bfdf_2132d8e1ce56 7025b240_fdc3_cf68_b72f_f41dac94566b["json"] 66049afc_0602_fbed_73fa_20a4904169e2 --> 7025b240_fdc3_cf68_b72f_f41dac94566b cccbe73e_4644_7211_4d55_e8fb133a8014["abc"] 66049afc_0602_fbed_73fa_20a4904169e2 --> cccbe73e_4644_7211_4d55_e8fb133a8014 cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"] 66049afc_0602_fbed_73fa_20a4904169e2 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7 c990f2d7_9509_7cea_ca95_51ad57dbe5c6["functools"] 66049afc_0602_fbed_73fa_20a4904169e2 --> c990f2d7_9509_7cea_ca95_51ad57dbe5c6 b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8["pathlib"] 66049afc_0602_fbed_73fa_20a4904169e2 --> b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] 66049afc_0602_fbed_73fa_20a4904169e2 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 6a4c8a76_d409_3b0b_3e3a_9dfaef8d20fb["yaml"] 66049afc_0602_fbed_73fa_20a4904169e2 --> 6a4c8a76_d409_3b0b_3e3a_9dfaef8d20fb 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"] 66049afc_0602_fbed_73fa_20a4904169e2 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7 91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"] 66049afc_0602_fbed_73fa_20a4904169e2 --> 91721f45_4909_e489_8c1f_084f8bd87145 75137834_4ba7_dc43_7ec5_182c05eceedf["langchain_core.exceptions"] 66049afc_0602_fbed_73fa_20a4904169e2 --> 75137834_4ba7_dc43_7ec5_182c05eceedf 36cce5da_d805_04c3_7e86_e1b4dd49b497["langchain_core.load"] 66049afc_0602_fbed_73fa_20a4904169e2 --> 36cce5da_d805_04c3_7e86_e1b4dd49b497 fc383c03_4b29_7c03_c489_626a968d8d03["langchain_core.output_parsers.base"] 66049afc_0602_fbed_73fa_20a4904169e2 --> fc383c03_4b29_7c03_c489_626a968d8d03 style 66049afc_0602_fbed_73fa_20a4904169e2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Base class for prompt templates."""
from __future__ import annotations
import builtins # noqa: TC003
import contextlib
import json
from abc import ABC, abstractmethod
from collections.abc import Mapping # noqa: TC003
from functools import cached_property
from pathlib import Path
from typing import TYPE_CHECKING, Any, Generic, TypeVar, cast
import yaml
from pydantic import BaseModel, ConfigDict, Field, model_validator
from typing_extensions import Self, override
from langchain_core.exceptions import ErrorCode, create_message
from langchain_core.load import dumpd
from langchain_core.output_parsers.base import BaseOutputParser # noqa: TC001
from langchain_core.prompt_values import (
ChatPromptValueConcrete,
PromptValue,
StringPromptValue,
)
from langchain_core.runnables import RunnableConfig, RunnableSerializable
from langchain_core.runnables.config import ensure_config
from langchain_core.utils.pydantic import create_model_v2
if TYPE_CHECKING:
from collections.abc import Callable
from langchain_core.documents import Document
FormatOutputType = TypeVar("FormatOutputType")
class BasePromptTemplate(
RunnableSerializable[dict, PromptValue], ABC, Generic[FormatOutputType]
):
"""Base class for all prompt templates, returning a prompt."""
input_variables: list[str]
"""A list of the names of the variables whose values are required as inputs to the
prompt.
"""
optional_variables: list[str] = Field(default=[])
"""A list of the names of the variables for placeholder or `MessagePlaceholder` that
are optional.
These variables are auto inferred from the prompt and user need not provide them.
"""
input_types: builtins.dict[str, Any] = Field(default_factory=dict, exclude=True)
"""A dictionary of the types of the variables the prompt template expects.
If not provided, all variables are assumed to be strings.
"""
// ... (411 more lines)
Domain
Subdomains
Classes
Dependencies
- abc
- builtins
- collections.abc
- contextlib
- functools
- json
- langchain_core.documents
- langchain_core.exceptions
- langchain_core.load
- langchain_core.output_parsers.base
- langchain_core.prompt_values
- langchain_core.runnables
- langchain_core.runnables.config
- langchain_core.utils.pydantic
- pathlib
- pydantic
- typing
- typing_extensions
- yaml
Source
Frequently Asked Questions
What does base.py do?
base.py is a source file in the langchain codebase, written in python. It belongs to the PromptManagement domain, ExampleSelection subdomain.
What functions are defined in base.py?
base.py defines 4 function(s): _get_document_info, aformat_document, collections, format_document.
What does base.py depend on?
base.py imports 19 module(s): abc, builtins, collections.abc, contextlib, functools, json, langchain_core.documents, langchain_core.exceptions, and 11 more.
Where is base.py in the architecture?
base.py is located at libs/core/langchain_core/prompts/base.py (domain: PromptManagement, subdomain: ExampleSelection, directory: libs/core/langchain_core/prompts).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free