DictPromptTemplate Class — langchain Architecture
Architecture documentation for the DictPromptTemplate class in dict.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 99b61388_a110_30d7_e5b6_3ec6b66bc790["DictPromptTemplate"] d31ac8f6_f369_3202_2fdc_84c37eba4e57["dict.py"] 99b61388_a110_30d7_e5b6_3ec6b66bc790 -->|defined in| d31ac8f6_f369_3202_2fdc_84c37eba4e57 a5f1df93_8834_6c58_c037_0fc392a9835a["input_variables()"] 99b61388_a110_30d7_e5b6_3ec6b66bc790 -->|method| a5f1df93_8834_6c58_c037_0fc392a9835a bb0b608c_59c9_0fe2_d2b0_9aac161c0550["format()"] 99b61388_a110_30d7_e5b6_3ec6b66bc790 -->|method| bb0b608c_59c9_0fe2_d2b0_9aac161c0550 d48a69cd_ae11_f9bf_fb23_97098938b638["aformat()"] 99b61388_a110_30d7_e5b6_3ec6b66bc790 -->|method| d48a69cd_ae11_f9bf_fb23_97098938b638 7c0e2e03_4dc8_1af5_a25e_fb968989eb1b["invoke()"] 99b61388_a110_30d7_e5b6_3ec6b66bc790 -->|method| 7c0e2e03_4dc8_1af5_a25e_fb968989eb1b 832b7244_18db_e78e_f6d9_b82d0e4f2f9d["_prompt_type()"] 99b61388_a110_30d7_e5b6_3ec6b66bc790 -->|method| 832b7244_18db_e78e_f6d9_b82d0e4f2f9d 2c3d9d5d_a379_f4c1_cbc9_f12e50727868["_serialized()"] 99b61388_a110_30d7_e5b6_3ec6b66bc790 -->|method| 2c3d9d5d_a379_f4c1_cbc9_f12e50727868 efad768e_97ce_ac68_c383_43899e7eb80b["is_lc_serializable()"] 99b61388_a110_30d7_e5b6_3ec6b66bc790 -->|method| efad768e_97ce_ac68_c383_43899e7eb80b 1f7a4e13_2c02_59ba_99f8_33074a09cf5c["get_lc_namespace()"] 99b61388_a110_30d7_e5b6_3ec6b66bc790 -->|method| 1f7a4e13_2c02_59ba_99f8_33074a09cf5c 218deeaf_ad68_ab9a_e897_774c93dec083["pretty_repr()"] 99b61388_a110_30d7_e5b6_3ec6b66bc790 -->|method| 218deeaf_ad68_ab9a_e897_774c93dec083
Relationship Graph
Source Code
libs/core/langchain_core/prompts/dict.py lines 18–97
class DictPromptTemplate(RunnableSerializable[dict, dict]):
"""Template represented by a dictionary.
Recognizes variables in f-string or mustache formatted string dict values.
Does NOT recognize variables in dict keys. Applies recursively.
"""
template: dict[str, Any]
template_format: Literal["f-string", "mustache"]
@property
def input_variables(self) -> list[str]:
"""Template input variables."""
return _get_input_variables(self.template, self.template_format)
def format(self, **kwargs: Any) -> dict[str, Any]:
"""Format the prompt with the inputs.
Returns:
A formatted dict.
"""
return _insert_input_variables(self.template, kwargs, self.template_format)
async def aformat(self, **kwargs: Any) -> dict[str, Any]:
"""Format the prompt with the inputs.
Returns:
A formatted dict.
"""
return self.format(**kwargs)
@override
def invoke(
self, input: dict, config: RunnableConfig | None = None, **kwargs: Any
) -> dict:
return self._call_with_config(
lambda x: self.format(**x),
input,
ensure_config(config),
run_type="prompt",
serialized=self._serialized,
**kwargs,
)
@property
def _prompt_type(self) -> str:
return "dict-prompt"
@cached_property
def _serialized(self) -> dict[str, Any]:
# self is always a Serializable object in this case, thus the result is
# guaranteed to be a dict since dumpd uses the default callback, which uses
# obj.to_json which always returns TypedDict subclasses
return cast("dict[str, Any]", dumpd(self))
@classmethod
def is_lc_serializable(cls) -> bool:
"""Return `True` as this class is serializable."""
return True
@classmethod
def get_lc_namespace(cls) -> list[str]:
"""Get the namespace of the LangChain object.
Returns:
`["langchain_core", "prompts", "dict"]`
"""
return ["langchain_core", "prompts", "dict"]
def pretty_repr(self, *, html: bool = False) -> str:
"""Human-readable representation.
Args:
html: Whether to format as HTML.
Returns:
Human-readable representation.
"""
raise NotImplementedError
Defined In
Source
Frequently Asked Questions
What is the DictPromptTemplate class?
DictPromptTemplate is a class in the langchain codebase, defined in libs/core/langchain_core/prompts/dict.py.
Where is DictPromptTemplate defined?
DictPromptTemplate is defined in libs/core/langchain_core/prompts/dict.py at line 18.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free