format() — langchain Function Reference
Architecture documentation for the format() function in few_shot.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 864942bd_f263_4aa9_f653_51867453f26e["format()"] 4a8cd875_a116_c859_9f43_6737c2811ee4["FewShotPromptTemplate"] 864942bd_f263_4aa9_f653_51867453f26e -->|defined in| 4a8cd875_a116_c859_9f43_6737c2811ee4 64d896c9_2471_3d82_ede6_85174aebb966["format()"] 64d896c9_2471_3d82_ede6_85174aebb966 -->|calls| 864942bd_f263_4aa9_f653_51867453f26e 9b7b7938_0729_de4a_3a6b_f2ebfcbf1f8a["_get_examples()"] 864942bd_f263_4aa9_f653_51867453f26e -->|calls| 9b7b7938_0729_de4a_3a6b_f2ebfcbf1f8a 64d896c9_2471_3d82_ede6_85174aebb966["format()"] 864942bd_f263_4aa9_f653_51867453f26e -->|calls| 64d896c9_2471_3d82_ede6_85174aebb966 style 864942bd_f263_4aa9_f653_51867453f26e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/prompts/few_shot.py lines 179–205
def format(self, **kwargs: Any) -> str:
"""Format the prompt with inputs generating a string.
Use this method to generate a string representation of a prompt.
Args:
**kwargs: Keyword arguments to use for formatting.
Returns:
A string representation of the prompt.
"""
kwargs = self._merge_partial_and_user_variables(**kwargs)
# Get the examples to use.
examples = self._get_examples(**kwargs)
examples = [
{k: e[k] for k in self.example_prompt.input_variables} for e in examples
]
# Format the examples.
example_strings = [
self.example_prompt.format(**example) for example in examples
]
# Create the overall template.
pieces = [self.prefix, *example_strings, self.suffix]
template = self.example_separator.join([piece for piece in pieces if piece])
# Format the template with the input variables.
return DEFAULT_FORMATTER_MAPPING[self.template_format](template, **kwargs)
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does format() do?
format() is a function in the langchain codebase, defined in libs/core/langchain_core/prompts/few_shot.py.
Where is format() defined?
format() is defined in libs/core/langchain_core/prompts/few_shot.py at line 179.
What does format() call?
format() calls 2 function(s): _get_examples, format.
What calls format()?
format() is called by 1 function(s): format.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free