BaseChatPromptTemplate Class — langchain Architecture
Architecture documentation for the BaseChatPromptTemplate class in chat.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 93017235_36b7_3b85_820e_aa7d145183e5["BaseChatPromptTemplate"] dddce6a3_2420_c71d_01fe_f214c3eb2503["BasePromptTemplate"] 93017235_36b7_3b85_820e_aa7d145183e5 -->|extends| dddce6a3_2420_c71d_01fe_f214c3eb2503 d735cdf0_4dd6_b10d_3d65_7f753809639d["chat.py"] 93017235_36b7_3b85_820e_aa7d145183e5 -->|defined in| d735cdf0_4dd6_b10d_3d65_7f753809639d 4fe4513e_3354_db06_9595_6bda41c81ffa["lc_attributes()"] 93017235_36b7_3b85_820e_aa7d145183e5 -->|method| 4fe4513e_3354_db06_9595_6bda41c81ffa 08b4874f_15ee_e20e_22dd_dc40f35fb150["format()"] 93017235_36b7_3b85_820e_aa7d145183e5 -->|method| 08b4874f_15ee_e20e_22dd_dc40f35fb150 a2b4f8ac_2b89_d468_ad91_8d0355c8d508["aformat()"] 93017235_36b7_3b85_820e_aa7d145183e5 -->|method| a2b4f8ac_2b89_d468_ad91_8d0355c8d508 e9411289_e300_3889_9890_8b2d1e616969["format_prompt()"] 93017235_36b7_3b85_820e_aa7d145183e5 -->|method| e9411289_e300_3889_9890_8b2d1e616969 54d4332a_99bc_4cc5_b549_4f0b0cddfb16["aformat_prompt()"] 93017235_36b7_3b85_820e_aa7d145183e5 -->|method| 54d4332a_99bc_4cc5_b549_4f0b0cddfb16 9e40405f_9251_5a40_24a2_2959e7b39db7["format_messages()"] 93017235_36b7_3b85_820e_aa7d145183e5 -->|method| 9e40405f_9251_5a40_24a2_2959e7b39db7 888559a1_7b1d_0bba_1c91_f63624147a91["aformat_messages()"] 93017235_36b7_3b85_820e_aa7d145183e5 -->|method| 888559a1_7b1d_0bba_1c91_f63624147a91 47fe42aa_c8e0_87b2_ad04_4343c7ef26cb["pretty_repr()"] 93017235_36b7_3b85_820e_aa7d145183e5 -->|method| 47fe42aa_c8e0_87b2_ad04_4343c7ef26cb 418ca2f5_d22d_00d9_07a1_bc3639de0847["pretty_print()"] 93017235_36b7_3b85_820e_aa7d145183e5 -->|method| 418ca2f5_d22d_00d9_07a1_bc3639de0847
Relationship Graph
Source Code
libs/core/langchain_core/prompts/chat.py lines 690–776
class BaseChatPromptTemplate(BasePromptTemplate, ABC):
"""Base class for chat prompt templates."""
@property
@override
def lc_attributes(self) -> dict:
return {"input_variables": self.input_variables}
def format(self, **kwargs: Any) -> str:
"""Format the chat template into a string.
Args:
**kwargs: Keyword arguments to use for filling in template variables in all
the template messages in this chat template.
Returns:
Formatted string.
"""
return self.format_prompt(**kwargs).to_string()
async def aformat(self, **kwargs: Any) -> str:
"""Async format the chat template into a string.
Args:
**kwargs: Keyword arguments to use for filling in template variables in all
the template messages in this chat template.
Returns:
Formatted string.
"""
return (await self.aformat_prompt(**kwargs)).to_string()
def format_prompt(self, **kwargs: Any) -> ChatPromptValue:
"""Format prompt.
Should return a `ChatPromptValue`.
Args:
**kwargs: Keyword arguments to use for formatting.
"""
messages = self.format_messages(**kwargs)
return ChatPromptValue(messages=messages)
async def aformat_prompt(self, **kwargs: Any) -> ChatPromptValue:
"""Async format prompt.
Should return a `ChatPromptValue`.
Args:
**kwargs: Keyword arguments to use for formatting.
"""
messages = await self.aformat_messages(**kwargs)
return ChatPromptValue(messages=messages)
@abstractmethod
def format_messages(self, **kwargs: Any) -> list[BaseMessage]:
"""Format kwargs into a list of messages.
Returns:
List of `BaseMessage` objects.
"""
async def aformat_messages(self, **kwargs: Any) -> list[BaseMessage]:
"""Async format kwargs into a list of messages.
Returns:
List of `BaseMessage` objects.
"""
return self.format_messages(**kwargs)
def pretty_repr(
self,
html: bool = False, # noqa: FBT001,FBT002
) -> str:
"""Human-readable representation.
Args:
html: Whether to format as HTML.
Returns:
Human-readable representation.
Defined In
Extends
Source
Frequently Asked Questions
What is the BaseChatPromptTemplate class?
BaseChatPromptTemplate is a class in the langchain codebase, defined in libs/core/langchain_core/prompts/chat.py.
Where is BaseChatPromptTemplate defined?
BaseChatPromptTemplate is defined in libs/core/langchain_core/prompts/chat.py at line 690.
What does BaseChatPromptTemplate extend?
BaseChatPromptTemplate extends BasePromptTemplate.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free