LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-corepromptsfew_shot
    Moduleā—Since v0.1

    few_shot

    Prompt template that contains few shot examples.

    Attributes

    Functions

    Classes

    View source on GitHub
    attribute
    DEFAULT_FORMATTER_MAPPING: dict[str, Callable[..., str]]
    function
    deprecated
    function
    get_buffer_string
    function
    check_valid_template
    function
    get_template_variables
    class
    BaseExampleSelector
    class
    BaseMessage
    class
    BaseChatPromptTemplate
    class
    BaseMessagePromptTemplate
    class
    PromptTemplate
    class
    StringPromptTemplate
    class
    FewShotPromptTemplate
    class
    FewShotChatMessagePromptTemplate

    Decorator to mark a function, a class, or a property as deprecated.

    When deprecating a classmethod, a staticmethod, or a property, the @deprecated decorator should go under @classmethod and @staticmethod (i.e., deprecated should directly decorate the underlying callable), but over @property.

    When deprecating a class C intended to be used as a base class in a multiple inheritance hierarchy, C must define an __init__ method (if C instead inherited its __init__ from its own base class, then @deprecated would mess up __init__ inheritance when installing its own (deprecation-emitting) C.__init__).

    Parameters are the same as for warn_deprecated, except that obj_type defaults to 'class' if decorating a class, 'attribute' if decorating a property, and 'function' otherwise.

    Convert a sequence of messages to strings and concatenate them into one string.

    Check that template string is valid.

    Get the variables from the template.

    Interface for selecting examples to include in prompts.

    Base abstract message class.

    Messages are the inputs and outputs of a chat model.

    Examples include HumanMessage, AIMessage, and SystemMessage.

    Base class for chat prompt templates.

    Base class for message prompt templates.

    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.

    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.

    String prompt that exposes the format method, returning a prompt.

    Prompt template that contains few shot examples.

    Chat prompt template that supports few-shot examples.

    The high level structure of produced by this prompt template is a list of messages consisting of prefix message(s), example message(s), and suffix message(s).

    This structure enables creating a conversation with intermediate examples like:

    System: You are a helpful AI Assistant
    
    Human: What is 2+2?
    
    AI: 4
    
    Human: What is 2+3?
    
    AI: 5
    
    Human: What is 4+4?

    This prompt template can be used to generate a fixed list of examples or else to dynamically select examples based on the input.