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_shotFewShotChatMessagePromptTemplate
    Class●Since v0.1

    FewShotChatMessagePromptTemplate

    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.

    Copy
    FewShotChatMessagePromptTemplate(
      self,
      *args: Any = (),
      **kwargs: Any = {}
    )

    Bases

    BaseChatPromptTemplate_FewShotPromptTemplateMixin

    Used in Docs

    • Fiddler integration

    Attributes

    attribute
    input_variables: list[str]

    A list of the names of the variables the prompt template will use to pass to the example_selector, if provided.

    attribute
    example_prompt: BaseMessagePromptTemplate | BaseChatPromptTemplate

    The class to format each example.

    attribute
    model_config

    Methods

    method
    is_lc_serializable

    Return False as this class is not serializable.

    method
    format_messages

    Format kwargs into a list of messages.

    method
    aformat_messages

    Async format kwargs into a list of messages.

    method
    format

    Format the prompt with inputs generating a string.

    Use this method to generate a string representation of a prompt consisting of chat messages.

    Useful for feeding into a string-based completion language model or debugging.

    method
    aformat

    Async format the prompt with inputs generating a string.

    Use this method to generate a string representation of a prompt consisting of chat messages.

    Useful for feeding into a string-based completion language model or debugging.

    method
    pretty_repr

    Return a pretty representation of the prompt template.

    Inherited fromBaseChatPromptTemplate

    Attributes

    Alc_attributes: dict

    Methods

    Mformat_prompt
    —

    Format prompt.

    Maformat_prompt
    —

    Async format prompt.

    Mpretty_print
    —

    Print a human-readable representation.

    Inherited fromBasePromptTemplate

    Attributes

    Aoptional_variables: list[str]
    —

    A list of the names of the variables for placeholder or MessagePlaceholder that

    Ainput_types: builtins.dict[str, Any]
    —

    A dictionary of the types of the variables the prompt template expects.

    Aoutput_parser: BaseOutputParser | None
    —

    How to parse the output of calling an LLM on this formatted prompt.

    Apartial_variables: Mapping[str, Any]
    —

    A dictionary of the partial variables the prompt template carries.

    Ametadata: builtins.dict[str, Any] | None
    —

    Metadata to be used for tracing.

    Atags: list[str] | None
    —

    Tags to be used for tracing.

    AOutputType: Any
    —

    Return the output type of the prompt.

    Methods

    Mvalidate_variable_names
    —

    Validate variable names do not include restricted names.

    Mget_lc_namespace
    —

    Get the namespace of the LangChain object.

    Mget_input_schema
    —

    Get the input schema for the prompt.

    Minvoke
    —

    Invoke the prompt.

    Mainvoke
    —

    Async invoke the prompt.

    Mformat_prompt
    —

    Create PromptValue.

    Maformat_prompt
    —

    Async create PromptValue.

    Mpartial
    —

    Return a partial of the prompt template.

    Mdict
    —

    Return dictionary representation of prompt.

    Msave
    —

    Save the prompt.

    Inherited fromRunnableSerializable

    Attributes

    Aname: str | None
    —

    The name of the Runnable.

    Methods

    Mto_json
    —

    Serialize the Runnable to JSON.

    Mconfigurable_fields
    —

    Configure particular Runnable fields at runtime.

    Mconfigurable_alternatives
    —

    Configure alternatives for Runnable objects that can be set at runtime.

    Inherited fromSerializable

    Attributes

    Alc_secrets: dict[str, str]
    —

    A map of constructor argument names to secret ids.

    Alc_attributes: dict
    —

    List of attribute names that should be included in the serialized kwargs.

    Methods

    Mget_lc_namespace
    —

    Get the namespace of the LangChain object.

    Mlc_id
    —

    Return a unique identifier for this class for serialization purposes.

    Mto_json
    —

    Serialize the object to JSON.

    Mto_json_not_implemented
    —

    Serialize a "not implemented" object.

    Inherited fromRunnable

    Attributes

    Aname: str | None
    —

    The name of the Runnable. Used for debugging and tracing.

    AInputType: type[Input]
    —

    Input type.

    AOutputType: type[Output]
    —

    Output Type.

    Ainput_schema: type[BaseModel]
    —

    The type of input this Runnable accepts specified as a Pydantic model.

    Aoutput_schema: type[BaseModel]
    —

    Output schema.

    Aconfig_specs: list[ConfigurableFieldSpec]
    —

    List configurable fields for this Runnable.

    Methods

    Mget_name
    —

    Get the name of the Runnable.

    Mget_input_schema
    —

    Get a Pydantic model that can be used to validate input to the Runnable.

    Mget_input_jsonschema
    —

    Get a JSON schema that represents the input to the Runnable.

    Mget_output_schema
    —

    Get a Pydantic model that can be used to validate output to the Runnable.

    Mget_output_jsonschema
    —

    Get a JSON schema that represents the output of the Runnable.

    Mconfig_schema
    —

    The type of config this Runnable accepts specified as a Pydantic model.

    Mget_config_jsonschema
    —

    Get a JSON schema that represents the config of the Runnable.

    Mget_graph
    —

    Return a graph representation of this Runnable.

    Mget_prompts
    —

    Return a list of prompts used by this Runnable.

    Mpipe
    —

    Pipe Runnable objects.

    Mpick
    —

    Pick keys from the output dict of this Runnable.

    Massign
    —

    Assigns new fields to the dict output of this Runnable.

    Minvoke
    —

    Transform a single input into an output.

    Mainvoke
    —

    Transform a single input into an output.

    Mbatch
    —

    Default implementation runs invoke in parallel using a thread pool executor.

    Mbatch_as_completed
    —

    Run invoke in parallel on a list of inputs.

    Mabatch
    —

    Default implementation runs ainvoke in parallel using asyncio.gather.

    Mabatch_as_completed
    —

    Run ainvoke in parallel on a list of inputs.

    Mstream
    —

    Default implementation of stream, which calls invoke.

    Mastream
    —

    Default implementation of astream, which calls ainvoke.

    Mastream_log
    —

    Stream all output from a Runnable, as reported to the callback system.

    Mastream_events
    —

    Generate a stream of events.

    Mtransform
    —

    Transform inputs to outputs.

    Matransform
    —

    Transform inputs to outputs.

    Mbind
    —

    Bind arguments to a Runnable, returning a new Runnable.

    Mwith_config
    —

    Bind config to a Runnable, returning a new Runnable.

    Mwith_listeners
    —

    Bind lifecycle listeners to a Runnable, returning a new Runnable.

    Mwith_alisteners
    —

    Bind async lifecycle listeners to a Runnable.

    Mwith_types
    —

    Bind input and output types to a Runnable, returning a new Runnable.

    Mwith_retry
    —

    Create a new Runnable that retries the original Runnable on exceptions.

    Mmap
    —

    Return a new Runnable that maps a list of inputs to a list of outputs.

    Mwith_fallbacks
    —

    Add fallbacks to a Runnable, returning a new Runnable.

    Mas_tool
    —

    Create a BaseTool from a Runnable.

    View source on GitHub