Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mlconnor opened this issue Sep 26, 2023 · 9 comments
Closed

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

mlconnor opened this issue Sep 26, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@mlconnor
Copy link

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.

@HenryHengZJ
Copy link
Contributor

The prompt you mean is that System Message?
image

or Prompt Template?
image

@HenryHengZJ HenryHengZJ added the bug Something isn't working label Sep 26, 2023
@yavisht
Copy link
Contributor

yavisht commented Oct 12, 2023

+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
Copy link
Contributor

yavisht commented Oct 12, 2023

@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

@HenryHengZJ
Copy link
Contributor

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

JohnBQuinn pushed a commit to JohnBQuinn/Flowise that referenced this issue Jun 7, 2024
Signed-off-by: Carson Yang <yangchuansheng33@gmail.com>
@ryanhalliday
Copy link
Contributor

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!

@HenryHengZJ
Copy link
Contributor

PR #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.

@dkindlund
Copy link
Contributor

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

@dkindlund
Copy link
Contributor

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants