/n8n-tutorials

How to fix broken variable interpolation in system prompts in n8n?

Learn how to fix broken variable interpolation in n8n system prompts with simple steps to restore accurate workflows and reliable automation.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free consultation

How to fix broken variable interpolation in system prompts in n8n?

The direct fix is: when a system prompt in n8n doesn’t interpolate variables (expressions like {{$json.xxx}}), you must switch the field to Expression mode, or wrap your text inside an expression using backticks and concatenation. System Prompt fields in some AI nodes look like normal text fields, but they do not parse inline {{ }} expressions unless the field is toggled to Expression mode. You can always force interpolation by clicking “Add Expression” and writing the whole prompt as a single expression string.

 

Why this happens

 

In n8n, every field is either in Raw Text mode or Expression mode. Raw Text mode will treat {{ $json.something }} literally as text. It does not interpolate it. Expression mode actually evaluates the JavaScript-like expression engine and returns the final string.

  • Regular text fields evaluate expressions inline.
  • Some system prompt fields in AI nodes treat text as literal unless the whole field is explicitly turned into an expression.

That is why it “looks like” variable interpolation is broken — but the field is just not set to Expression mode.

 

How to fix it properly (production‑safe)

 

Use one of the two real working patterns below. Both are standard practice in complex production n8n automations.

  • Fix #1: Click “Add Expression” and build the whole prompt as one expression
    This forces evaluation 100% of the time.

    Example:

    \`\`\`js // This is a single expression that returns a final string `You are a helpful assistant. Here is the user's request: ${$json.request}.` \`\`\`
  • Fix #2: Split into multiple expressions inside a string (if the node allows inline)
    This only works if the specific AI node supports inline expressions in text mode. Some do, some do not.

    Example:

    \`\`\` // Only works if the field supports inline {{ }} syntax You are a helpful assistant. The user said: {{$json.request}} \`\`\` If you try this and see {{$json.request}} appear literally, it means the field does NOT support inline expressions and you must use Fix #1.

 

Best practice for system prompts across workflows

 

In real production environments, the most stable approach is always to use an expression wrapping the entire prompt. It avoids edge cases where a field silently stops processing inline expressions after updates, or behaves differently between cloud and self‑hosted n8n versions.

  • Build the prompt in a Function node (string templates are cleaner).
  • Store it in $json.prompt.
  • In the AI node’s system prompt field, set Expression mode:
// Clean, fully controlled source
$json.prompt

This ensures you know exactly what is being passed to the AI node, with zero ambiguity.

 

Final practical takeaway

 

The fix is to force the field into Expression mode. Inline {{ }} syntax inside text fields in system prompts is not always parsed by n8n, so you must explicitly add an expression or build the entire prompt as a template string. That’s the reliable production-safe approach.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022