Flowise icon indicating copy to clipboard operation
Flowise copied to clipboard

[BUG] Need to escape or ignore curly braces in prompts

Open mlconnor opened this issue 2 years ago • 5 comments

Describe the bug Need to be able to escape curly braces so that JSON can be used in prompts. Either that, or have Flowise ignore all text it perceives as variables so long as there isn't a corresponding variable.

To Reproduce Steps to reproduce the behavior:

  1. Create a flow with a prompt
  2. Paste a JSON object in the prompt {"foo":"bar"}
  3. Run the flow

Expected behavior I would expect Flowise to ignore any {values} that don't have a corresponding variable, or give me a facility to escape the value. Instead it prints Please provide Prompt Values for: ...

Flow If applicable, add exported flow in order to help replicating the problem.

Setup

  • Installation [e.g. docker, npx flowise start, yarn start]
  • Flowise Version [e.g. 1.2.11]
  • OS: [e.g. macOS, Windows, Linux]
  • Browser [e.g. chrome, safari]

Additional context Add any other context about the problem here.

mlconnor avatar Sep 26 '23 13:09 mlconnor

The prompt you mean is that System Message? image

or Prompt Template? image

HenryHengZJ avatar Sep 26 '23 23:09 HenryHengZJ

+1 for this bug, need a way to escape {} in prompt. Check how to reproduce. Also attaching a working version from OAI playground.

Screen Shot 2023-10-12 at 11 54 06 am Screen Shot 2023-10-12 at 11 54 22 am Screen Shot 2023-10-12 at 11 55 21 am

yavisht avatar Oct 12 '23 00:10 yavisht

@mlconnor

Here is a workaround - just url encode the json response for now and try it

This technique will use more tokens but works well.

for e.g.

{"foo":"bar"}
%7B%22foo%22%3A%22bar%22%7D

Got it working with my example in my previous message

Screen Shot 2023-10-12 at 12 18 13 pm Screen Shot 2023-10-12 at 12 12 48 pm

yavisht avatar Oct 12 '23 01:10 yavisht

@yavisht thanks for the workaround! will come up with a proper fix

HenryHengZJ avatar Oct 15 '23 11:10 HenryHengZJ

You can use double curly brackets to escape JSON {{ "myJson": "value" }} - sort of...

You may want to consider that as the encoding like %7B relies on the LLM un-encoding it for you, so be sure to add as json to your prompt if you use that.


This works with the "Chat Prompt Template" but not the "Prompt Template" because it attempts to validate the data.

You do have to remove the unwanted Prompt Value inputs though from the "Format Prompt Values" popup.

chat prompt template prompt template

This is because Langchain JS re-implements the Python f-strings syntax - see prompt.ts and template.ts

As for the validation the "Prompt Template" causes, that should be fixed or removed. It's located in LLMChain.ts. Same as below this is a case of inconsistent parsing.

It could be an idea to move to the mustache template syntax, which Langchain JS supports, would be more familiar to JS developers and perhaps more powerful/flexible than f-strings. Huge change though so 🤷


This also brings up an interesting bug in the prompt values section - the following template creates the following variables:

{ aVariable }
{{ hello }}
image

This is a case of inconsistent template parsing, I didn't track that one down.


Hope all that helps!

ryanhalliday avatar Sep 06 '24 18:09 ryanhalliday

PR https://github.com/FlowiseAI/Flowise/pull/3901 opened to solve this.

Fix: Identify if there is a colon : within the curly brackets, if yes, we will not extract the value as variable.

HenryHengZJ avatar Jan 20 '25 18:01 HenryHengZJ

@HenryHengZJ , seeing this error crop up again in version 2.2.5 -- FYI.

dkindlund avatar Feb 06 '25 15:02 dkindlund

Okay, so previously, I had all my prompts encased in {{ and }} -- but version 2.2.5 now broke this construct. Requiring a colon to be present inside my text is a non-starter -- it breaks the fundamental logic of my prompts. Is there any other workaround?

dkindlund avatar Feb 06 '25 15:02 dkindlund

Okay, URL encoding is my only option -- frustrating but doable for now...

dkindlund avatar Feb 06 '25 16:02 dkindlund

@HenryHengZJ - This change broke our prompts that had {{ and }} as a way to escape json. What is the fix now?

@dkindlund 👍

vijaykammili avatar Mar 18 '25 02:03 vijaykammili

opened another fix here: https://github.com/FlowiseAI/Flowise/pull/4252

this prevents processing double curly brackets, in other words, we only transform single curly brackets with colon. For example:

{ answer: This is AI }

to

{{ answer: This is AI }}

HenryHengZJ avatar Apr 04 '25 06:04 HenryHengZJ

I have a system prompt which has JSON format like below System Prompt

Extract the product and color from the user input.


Output JSON in this format:


{
  "product": "name of product",
  "color": "color mentioned"
}


if not found, set value to null.

Human Prompt: Product color is red and product is water bottle

I get below error

Error buildAgentGraph - Error: LLM Node input variables values are not provided! Required: "product": "name of product", "color": "color mentioned" { "product": "name of product", "color": "color mentioned" }, Provided: . Missing: "product": "name of product", "color": "color mentioned" { "product": "name of product", "color": "color mentioned" }

If I change the system prompt to below, it works fine.


%7B
  "product": "name of product",
  "color": "color mentioned"
%7D

sjani-fsai avatar May 30 '25 00:05 sjani-fsai