Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions docs/docs/Components/components-prompts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`. <PartialCurlyBraces /> |
| 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}`. <PartialCurlyBraces /> |
| 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

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions docs/docs/Support/release-notes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion docs/docs/_partial-escape-curly-braces.mdx
Original file line number Diff line number Diff line change
@@ -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}`.
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).
Loading