langchain.prompts.chat.BaseChatPromptTemplate¶

class langchain.prompts.chat.BaseChatPromptTemplate(*, input_variables: List[str], output_parser: Optional[BaseOutputParser] = None, partial_variables: Mapping[str, Union[str, Callable[[], str]]] = None)[source]¶

Bases: BasePromptTemplate, ABC

Base class for chat prompt templates.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param input_variables: List[str] [Required]¶

A list of the names of the variables the prompt template expects.

param output_parser: Optional[BaseOutputParser] = None¶

How to parse the output of calling an LLM on this formatted prompt.

param partial_variables: Mapping[str, Union[str, Callable[[], str]]] [Optional]¶
dict(**kwargs: Any) Dict¶

Return dictionary representation of prompt.

format(**kwargs: Any) str[source]¶

Format the chat template into a string.

Parameters

**kwargs – keyword arguments to use for filling in template variables in all the template messages in this chat template.

Returns

formatted string

abstract format_messages(**kwargs: Any) List[BaseMessage][source]¶

Format kwargs into a list of messages.

format_prompt(**kwargs: Any) PromptValue[source]¶

Format prompt. Should return a PromptValue. :param **kwargs: Keyword arguments to use for formatting.

Returns

PromptValue.

invoke(input: Dict, config: langchain.schema.runnable.RunnableConfig | None = None) PromptValue¶
partial(**kwargs: Union[str, Callable[[], str]]) BasePromptTemplate¶

Return a partial of the prompt template.

save(file_path: Union[Path, str]) None¶

Save the prompt.

Parameters

file_path – Path to directory to save prompt to.

Example: .. code-block:: python

prompt.save(file_path=”path/prompt.yaml”)

to_json() Union[SerializedConstructor, SerializedNotImplemented]¶
to_json_not_implemented() SerializedNotImplemented¶
validator validate_variable_names  »  all fields¶

Validate variable names do not include restricted names.

property lc_attributes: Dict¶

Return a list of attribute names that should be included in the serialized kwargs. These attributes must be accepted by the constructor.

property lc_namespace: List[str]¶

Return the namespace of the langchain object. eg. [“langchain”, “llms”, “openai”]

property lc_secrets: Dict[str, str]¶

Return a map of constructor argument names to secret ids. eg. {“openai_api_key”: “OPENAI_API_KEY”}

property lc_serializable: bool¶

Return whether or not the class is serializable.

model Config¶

Bases: object

Configuration for this pydantic object.

arbitrary_types_allowed = True¶