Home / Function/ from_examples() — langchain Function Reference

from_examples() — langchain Function Reference

Architecture documentation for the from_examples() function in prompt.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  22573c07_8b17_9077_9444_ee546b219e79["from_examples()"]
  21bd3731_3333_8ace_7023_5dd43ed308cf["PromptTemplate"]
  22573c07_8b17_9077_9444_ee546b219e79 -->|defined in| 21bd3731_3333_8ace_7023_5dd43ed308cf
  style 22573c07_8b17_9077_9444_ee546b219e79 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/prompts/prompt.py lines 204–233

    def from_examples(
        cls,
        examples: list[str],
        suffix: str,
        input_variables: list[str],
        example_separator: str = "\n\n",
        prefix: str = "",
        **kwargs: Any,
    ) -> PromptTemplate:
        """Take examples in list format with prefix and suffix to create a prompt.

        Intended to be used as a way to dynamically create a prompt from examples.

        Args:
            examples: List of examples to use in the prompt.
            suffix: String to go after the list of examples.

                Should generally set up the user's input.
            input_variables: A list of variable names the final prompt template will
                expect.
            example_separator: The separator to use in between examples.
            prefix: String that should go before any examples.

                Generally includes examples.

        Returns:
            The final prompt generated.
        """
        template = example_separator.join([prefix, *examples, suffix])
        return cls(input_variables=input_variables, template=template, **kwargs)

Subdomains

Frequently Asked Questions

What does from_examples() do?
from_examples() is a function in the langchain codebase, defined in libs/core/langchain_core/prompts/prompt.py.
Where is from_examples() defined?
from_examples() is defined in libs/core/langchain_core/prompts/prompt.py at line 204.

Analyze Your Own Codebase

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

Try Supermodel Free