Source code for langchain.prompts.prompt
"""Prompt schema definition."""
from __future__ import annotations
from pathlib import Path
from string import Formatter
from typing import Any, Dict, List, Optional, Union
from langchain.prompts.base import (
    DEFAULT_FORMATTER_MAPPING,
    StringPromptTemplate,
    _get_jinja2_variables_from_template,
    check_valid_template,
)
from langchain.pydantic_v1 import root_validator
[docs]class PromptTemplate(StringPromptTemplate):
    """A prompt template for a language model.
    A prompt template consists of a string template. It accepts a set of parameters
    from the user that can be used to generate a prompt for a language model.
    The template can be formatted using either f-strings (default) or jinja2 syntax.
    Example:
        .. code-block:: python
            from langchain.prompts import PromptTemplate
            # Instantiation using from_template (recommended)
            prompt = PromptTemplate.from_template("Say {foo}")
            prompt.format(foo="bar")
            # Instantiation using initializer
            prompt = PromptTemplate(input_variables=["foo"], template="Say {foo}")
    """
    @property
    def lc_attributes(self) -> Dict[str, Any]:
        return {
            "template_format": self.template_format,
        }
    input_variables: List[str]
    """A list of the names of the variables the prompt template expects."""
    template: str
    """The prompt template."""
    template_format: str = "f-string"
    """The format of the prompt template. Options are: 'f-string', 'jinja2'."""
    validate_template: bool = True
    """Whether or not to try validating the template."""
    def __add__(self, other: Any) -> PromptTemplate: