Flowise icon indicating copy to clipboard operation
Flowise copied to clipboard

[BUG] Invalid JSON - SyntaxError in ChatPromptTemplate

Open jpmin7 opened this issue 1 year ago • 1 comments

Describe the bug "Error: Invalid JSON in the ChatPromptTemplate's promptValues: SyntaxError: Unexpected token N in JSON at position xyz"

When asking a question that contains "ä", "ü", "ö" and "ß" the flow will return the above-mentioned error. Also, when the answer of the llm contains one of those characters, the next question will fail. With each try, the "JSON at position xyz" increases.

To Reproduce image

I set up a flow that retrieves documents with Supabase → filters the retrieved chunks with LLM Filter retriever -> puts those into the ChatPromptTemplate and finally into the conversation chain.

Asking questions that contain "ä", "ü", "ö" and "ß". And then ask second question.

Expected behavior Don't throw an error when using German.

Flow ExpNewRag Chatflow.json

jpmin7 avatar Feb 26 '24 11:02 jpmin7

Update: It seems that my first hypothesis is wrong. Rather I have the impression that the error occurs when the context window is breached.

When decreasing top k after the error, the flow manges to return the llm call.

jpmin7 avatar Feb 26 '24 17:02 jpmin7

Do you mean that Chat Prompt Template is not able to handle query that contains "ä", "ü", "ö" and "ß" ?

HenryHengZJ avatar Feb 29 '24 11:02 HenryHengZJ

That was my first hypothesis, but it seems more like when the context window is breached that the above error appears. Observation: I get the error. I reduce top K. The query runs without a problem.

Is there any way to debug or managed context length better?

jpmin7 avatar Mar 01 '24 10:03 jpmin7

I'd suggest turning on Debug mode to see the logs - https://docs.flowiseai.com/configuration/environment-variables#debug-and-logs and also Analytics - https://docs.flowiseai.com/using-flowise/analytic.

Closing the issue for now.

HenryHengZJ avatar Mar 03 '24 01:03 HenryHengZJ

Hey @HenryHengZJ,

the error logs are the following:

2024-03-04 22:30:28 [ERROR]: [server]: Error: Error: Invalid JSON in the PromptTemplate's promptValues: SyntaxError: Unexpected token z in JSON at position 39241 Error: Error: Invalid JSON in the PromptTemplate's promptValues: SyntaxError: Unexpected token z in JSON at position 39241 at buildFlow (/usr/local/lib/node_modules/flowise/dist/utils/index.js:333:19) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async App.buildChatflow (/usr/local/lib/node_modules/flowise/dist/index.js:1708:40) at async /usr/local/lib/node_modules/flowise/dist/index.js:1148:13

As mentioned, the error occurs when the content length (based on a high top k (e.g. 40 fails, 30 works sometime, 15 works most of the time) becomes too large.

Any idea what is going on?

Also, analytics with langfuse does not help since the the traces are not tracked when the flow fails.

jpmin7 avatar Mar 04 '24 22:03 jpmin7