Home / File/ prompt.py — langchain Source File

prompt.py — langchain Source File

Architecture documentation for prompt.py, a python file in the langchain codebase. 6 imports, 0 dependents.

File python LangChainCore ApiManagement 6 imports 1 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  29f4b428_e422_0e7b_baca_2d60df5da372["prompt.py"]
  927570d8_11a6_5c17_0f0d_80baae0c733e["pathlib"]
  29f4b428_e422_0e7b_baca_2d60df5da372 --> 927570d8_11a6_5c17_0f0d_80baae0c733e
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  29f4b428_e422_0e7b_baca_2d60df5da372 --> feec1ec4_6917_867b_d228_b134d0ff8099
  dd5e7909_a646_84f1_497b_cae69735550e["pydantic"]
  29f4b428_e422_0e7b_baca_2d60df5da372 --> dd5e7909_a646_84f1_497b_cae69735550e
  f85fae70_1011_eaec_151c_4083140ae9e5["typing_extensions"]
  29f4b428_e422_0e7b_baca_2d60df5da372 --> f85fae70_1011_eaec_151c_4083140ae9e5
  63c0f54d_151f_9725_3a6b_4790a2ff15b4["langchain_core.prompts.string"]
  29f4b428_e422_0e7b_baca_2d60df5da372 --> 63c0f54d_151f_9725_3a6b_4790a2ff15b4
  a8ec7563_2814_99b3_c6da_61c599efc542["langchain_core.runnables.config"]
  29f4b428_e422_0e7b_baca_2d60df5da372 --> a8ec7563_2814_99b3_c6da_61c599efc542
  style 29f4b428_e422_0e7b_baca_2d60df5da372 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Prompt schema definition."""

from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING, Any

from pydantic import BaseModel, model_validator
from typing_extensions import override

from langchain_core.prompts.string import (
    DEFAULT_FORMATTER_MAPPING,
    PromptTemplateFormat,
    StringPromptTemplate,
    check_valid_template,
    get_template_variables,
    mustache_schema,
)

if TYPE_CHECKING:
    from langchain_core.runnables.config import RunnableConfig


class PromptTemplate(StringPromptTemplate):
    """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), jinja2, or mustache
    syntax.

    !!! warning "Security"

        Prefer using `template_format='f-string'` instead of `template_format='jinja2'`,
        or make sure to NEVER accept jinja2 templates from untrusted sources as they may
        lead to arbitrary Python code execution.

        As of LangChain 0.0.329, Jinja2 templates will be rendered using Jinja2's
        SandboxedEnvironment by default. This sand-boxing should be treated as a
        best-effort approach rather than a guarantee of security, as it is an opt-out
        rather than opt-in approach.

        Despite the sandboxing, we recommend to never use jinja2 templates from
        untrusted sources.

    Example:
        ```python
        from langchain_core.prompts import PromptTemplate

        # Instantiation using from_template (recommended)
        prompt = PromptTemplate.from_template("Say {foo}")
        prompt.format(foo="bar")

        # Instantiation using initializer
        prompt = PromptTemplate(template="Say {foo}")
        ```
    """

    @property
// ... (253 more lines)

Domain

Subdomains

Functions

Classes

Dependencies

  • langchain_core.prompts.string
  • langchain_core.runnables.config
  • pathlib
  • pydantic
  • typing
  • typing_extensions

Frequently Asked Questions

What does prompt.py do?
prompt.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, ApiManagement subdomain.
What functions are defined in prompt.py?
prompt.py defines 1 function(s): langchain_core.
What does prompt.py depend on?
prompt.py imports 6 module(s): langchain_core.prompts.string, langchain_core.runnables.config, pathlib, pydantic, typing, typing_extensions.
Where is prompt.py in the architecture?
prompt.py is located at libs/core/langchain_core/prompts/prompt.py (domain: LangChainCore, subdomain: ApiManagement, directory: libs/core/langchain_core/prompts).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free