langchain.schema.prompt_template.BasePromptTemplate¶
- class langchain.schema.prompt_template.BasePromptTemplate(*, input_variables: List[str], output_parser: Optional[BaseOutputParser] = None, partial_variables: Mapping[str, Union[str, Callable[[], str]]] = None)[source]¶
Bases:
Serializable,Runnable[Dict,PromptValue],ABCBase class for all prompt templates, returning a prompt.
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[langchain.schema.output_parser.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]¶
- abstract 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")
- abstract format_prompt(**kwargs: Any) PromptValue[source]¶
Create Chat Messages.
- invoke(input: Dict, config: langchain.schema.runnable.RunnableConfig | None = None) PromptValue[source]¶
- partial(**kwargs: Union[str, Callable[[], str]]) BasePromptTemplate[source]¶
Return a partial of the prompt template.
- save(file_path: Union[Path, str]) None[source]¶
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[source]¶
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.