OpenAI Node Input Issue: Array Instead of String

Describe the problem/error/question

I’m struggling with getting a dynamically generated prompt to reach the OpenAI HTTP node. The goal: combine an original text with structured feedback, pass it as a single prompt to gpt-4-1106-preview, and get an optimized version of the text.

:white_check_mark: Setup (simplified)

  1. Google Sheets → provides generatedText
  2. Code Node → adds feedback as prompt
  3. Merge NodeCombine mode → All Possible Combinations
  4. Code7 Node → builds final prompt
  5. HTTP Request7 → should then correctly execute the combined prompts

What is the error message (if any)?

:x: Problem

Although Code7 outputs the correct prompt, the HTTP node sends an empty or incomplete value to OpenAI.

Response:

“Unfortunately, you have not provided any specific information or data that I could convert into an optimised JSON text.” (just in german)

Workflow

Information on your n8n setup

  • n8n version: 1.74.4
  • Database (default: SQLite): pinecone
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud
  • Operating system:

Since you are saying Code 7 outputs the correct prompt but fails at HTTP request it could be a referencing issue of the finalPrompt from the previous node. can you verify and revert

Hey,

this should be fine, but I’m new to n8n and maybe I did something wrong. Here’s a screenshot of the input, the node and the output (see ‘Content:’ where it says: Unfortunately, you did not provide any specific information or data that I could convert into an optimised JSON text).

You dont have a solution for me, right? :confused:

Sorry. Hadnt had time to come back to this thread. The latest screenshot is quite helpful. I think in the line where you have
“content”: “{{JSON.stringify($json.prompt)}}”
this could be the issue. this is turning your prompt into a quoted JSON string including extra quotes and escaping like this “"Du bist ein professioneller SEO-Texter…"”
The open AI is going nuts since its being passed a string inside a string.
Replace that line with
“content”: “={{ $json.prompt }}”
The = at the beginning is crucial — it tells n8n to evaluate the expression and inject the value directly, instead of treating it as static text. try it out and let me know

Hmm, unfortunately it doesnt work :confused:

The Code looks like that now:

{
  "model": "gpt-4-1106-preview",
  "max_tokens": 2000,
  "temperature": 0.2,
  "messages": [
    {
      "role": "system",
      "content": "Du bist ein professioneller SEO-Texter. Optimiere den folgenden JSON-Text anhand des Feedbacks. Verändere keine Überschriften oder Themen — passe nur Formulierungen, Stil und Details an. Gib ausschließlich den optimierten Text zurück."
    },
    {
      "role": "user",
      "content": "={{ $json.prompt }}"
    }
  ]
}

But the output is always the same. “Unfortunately, you did not provide any specific information or data that I could convert into an optimised JSON text”

Hi @delsupreme , Why dont you use the OpenAI node directly?!

something like this:

1 Like

can you retrace back and see whats the $json.prompt like in Code 7 output and could you also share what does the code look like for Merge2 and Code7. Basically I am trying to figure out how the shape of the input is whether the generatedText or feedback is inside nested keys

I have now set it up like this and it seems to work :slight_smile: Would you use different settings than I have here?

2 Likes

Glad it works,

Would you use different settings than I have here?

no just the same as attached here


If your issue got solved, please mark this reply as the solution :white_check_mark::pray:t2:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.