I looked through the first 5 google pages about this problem, talked to gpt yesterday for a few hours, no solution ever. So it is simply a bug.
Is there any way to “clean up” the code in another node?
I tried to get around the bug by using database Baserow in between and first save the text there, and retrieve it, but still once in a few times of bot responses, n8n recognizes that JSON is still invalid.
ERROR: JSON parameter need to be an valid JSON details:
NodeOperationError: JSON parameter need to be an valid JSON
at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/HttpRequest/V3/HttpRequestV3.node.js:1070:35)
at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:652:51)
at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:596:68
at processTicksAndRejections (node:internal/process/task_queues:96:5)
JSON that is causing the problem. According to the validators, it has the correct format:
[
{
"id":
1,
"order":
"1.00000000000000000000",
"Wiadomosc":
"wymień listę 10 komedii lat 80",
"Odpowiedz":
"The Breakfast Club 1985 Ferris Buellers Day Off 1986 Ghostbusters 1984 Airplane 1980 The Princess Bride 1987 Trading Places 1983 National Lampoons Vacation 1983 Caddyshack 1980 The Naked Gun From the Files of Police Squad 1988 This Is Spinal Tap 1984"
}
]
The whole core of communication of the upper weather branch with the last Signal node has been tested for several months and works without problems.
After adding the OpenAI node, Signal sometimes fails to parse the code and returns a JSON error.
If anyone knows how to effectively call a “check message” request, I’d be happy to learn.
BTW
With this I have the same problem, every few answers the same error appears. So it seems to me that the problem may be with the OpenAI output.
The whole workflow works for simple responses, the bot normally communicates through Signal (with or without code node). But when I write “list 10 movies of the 80s” a JSON error appears and the message is not delivered.
I applied such code on the node preceding the output and the same error appears:
Previously, using JavaScript code written by GPT, I replaced the characters " with spaces, and removed some “whitespace characters” and it did not help at all.
So currently, every 10s Schedule node trigger HTTP Request to Signald container, checking if there are new messages available. (I do not know how to trigger this type of workflow in a different way).
IF node, it forwards the entire message if it contains /gpt characters.
Next Code node extracts only the “message” part from the received string and removes the /gpt characters.
OpenAI node, gets the extracted clean message and completes the task.
The next Code block, is a suggested JSON to string conversion, which creates a string with “content” in the middle.
The last Code block extracts the “content” from the string and passes it to the HTTP Request.
The HTTP Request, sends a message through the Signald API to the Signal messenger.
The problem with JSON occurs behind the OpenAI node, I guess in every case.
It is worth adding that this workflow works and the error appears once every 5 messages. Usually when some lists of things appear I guess.
In theory all characters allowed but if you are starting your string with " it will expect the next " to be the end so you would need to need for these to make sure it is valid json.
Suppose I have an Input node, before the last node that sends everything to Signal.
If this Input node contains, for example, clear text, weather, etc, there is no problem and Signal delivers all the messages.
If I replace the Input node with an OpenAI node, then once in several responses, the Signal node returns an error.
If I insert a Code node between the OpenAI node and Signal node with code that removes the characters " from the response, it still does not help.
This does not affect the message structure in Signal node.