langchain.prompts.pipeline.PipelinePromptTemplate¶

class langchain.prompts.pipeline.PipelinePromptTemplate(*, input_variables: List[str], output_parser: Optional[BaseOutputParser] = None, partial_variables: Mapping[str, Union[str, Callable[[], str]]] = None, final_prompt: BasePromptTemplate, pipeline_prompts: List[Tuple[str, BasePromptTemplate]])[source]¶

Bases: BasePromptTemplate

A prompt template for composing multiple prompt templates together.

This can be useful when you want to reuse parts of prompts. A PipelinePrompt consists of two main parts:

  • final_prompt: This is the final prompt that is returned

  • pipeline_prompts: This is a list of tuples, consisting

    of a string (name) and a Prompt Template. Each PromptTemplate will be formatted and then passed to future prompt templates as a variable with the same name as name

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 final_prompt: langchain.schema.prompt_template.BasePromptTemplate [Required]¶

The final prompt that is returned.

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]¶
param pipeline_prompts: List[Tuple[str, langchain.schema.prompt_template.BasePromptTemplate]] [Required]¶

A list of tuples, consisting of a string (name) and a Prompt Template.

dict(**kwargs: Any) Dict¶

Return dictionary representation of prompt.

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

Format the prompt with the inputs.

Parameters

kwargs – Any arguments to be passed to the prompt template.

Returns

A formatted string.

Example:

prompt.format(variable1="foo")
format_prompt(**kwargs: Any) PromptValue[source]¶

Create Chat Messages.

validator get_input_variables  »  all fields[source]¶

Get input variables.

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¶