diff --git a/docs/docs/Components/components-prompts.mdx b/docs/docs/Components/components-prompts.mdx index 1974e85c524c..13a2364c4d8a 100644 --- a/docs/docs/Components/components-prompts.mdx +++ b/docs/docs/Components/components-prompts.mdx @@ -19,10 +19,10 @@ The **Prompt Template** component can also output variable instructions to other ## Prompt Template parameters -| Name | Display Name | Description | -|----------|----------------|-------------------------------------------------------------------| -| template | Template | Input parameter. Create a prompt template with dynamic variables in curly braces, such as `{VARIABLE_NAME}`. | -| prompt | Prompt Message | Output parameter. The built prompt message returned by the `build_prompt` method. | +| Name | Display Name | Description | +|---------------------|---------------------|-------------------------------------------------------------------| +| template | Template | Input parameter. Create a prompt template with dynamic variables in curly braces, such as `{VARIABLE_NAME}`. | +| use_double_brackets | Use Double Brackets | When enabled, use Mustache syntax `{{variable}}` instead of f-string syntax `{variable}`. For more information, see [Use Mustache templating in prompt templates](#use-mustache-templating-in-prompt-templates). | ## Define variables in prompts @@ -70,6 +70,39 @@ The following steps demonstrate how to add variables to a **Prompt Template** co You can add as many variables as you like in your template. For example, you could add variables for `{references}` and `{instructions}`, and then feed that information in from other components, such as **Text Input**, **URL**, or **Read File** components. +### Use Mustache templating in prompt templates + +F-string escaping can become confusing when you mix escaped braces with variables in the same template. +For example: + +```text +Generate a response in this JSON format: +{{"name": "{name}", "age": {age}, "city": "{city}"}} + +The user's name is {name}, age is {age}, and they live in {city}. +``` + +The characters `{{` and `}}` are escaped literal braces for the JSON structure, but `{name}` is a variable. +This can make prompts error-prone and difficult to parse. +Use [Mustache](https://mustache.github.io) in your prompt templates to make the differences clearer. + +To enable Mustache templating, do the following: + +1. In the **Prompt Template** component, enable **Use Double Brackets**. +2. In your prompt template, change the variables from `{variable}` to `{{variable}}`. + Mustache uses `{` `}` for literal braces and `{{variable}}` for variables. + + ```text + Generate a response in this JSON format: + {"name": "{{name}}", "age": {{age}}, "city": "{{city}}"} + + The user's name is {{name}}, age is {{age}}, and they live in {{city}}. + ``` + +3. Click **Check & Save**. + The component lints the template code and returns **Prompt is ready** if there are no errors. + Your prompt is now ready to use in a flow. + ## See also * [**LangChain Prompt Hub** component](/bundles-langchain#prompt-hub) diff --git a/docs/docs/Support/release-notes.mdx b/docs/docs/Support/release-notes.mdx index a6d889a94ae0..a445580c1032 100644 --- a/docs/docs/Support/release-notes.mdx +++ b/docs/docs/Support/release-notes.mdx @@ -54,6 +54,11 @@ For all changes, see the [Changelog](https://github.com/langflow-ai/langflow/rel ### New features and enhancements +- Mustache templating support for Prompt Template component + + The **Prompt Template** component now supports Mustache templating syntax. + Mustache templating eliminates the need to escape curly braces when including JSON structures in your prompts. For more information, see [Prompt Template](/components-prompts#use-mustache-templating-in-prompt-templates). + - Modular dependency installation for `langflow-base` The `langflow-base` package now supports modular dependency installation. diff --git a/docs/docs/_partial-escape-curly-braces.mdx b/docs/docs/_partial-escape-curly-braces.mdx index dc9d33c3e9bc..899c31071f40 100644 --- a/docs/docs/_partial-escape-curly-braces.mdx +++ b/docs/docs/_partial-escape-curly-braces.mdx @@ -1,2 +1,5 @@ If your template includes literal text and variables, you can use double curly braces to escape literal curly braces in the template and prevent interpretation of that text as a variable. -For example: `This is a template with {{literal text in curly braces}} and a {variable}`. \ No newline at end of file +For example: `This is a template with {{literal text in curly braces}} and a {variable}`. + +If your template contains many literal curly braces, such as JSON structures, consider using Mustache templating instead. +For more information, see [Use Mustache templating in prompt templates](/components-prompts#use-mustache-templating-in-prompt-templates). \ No newline at end of file