Using curly braces in an ai agent node fails

I understand that when using curly braces, the ai agents expect some kind of value such as {tools} inline with LangChain, however, I need to give the AI json data which includes the curly braces, in which case it fails, what is the solution?

For exmaple, if I say:

Here’s an example of JSON structure:
{
“name”: “John Doe”,
“age”: 30
}

It will fail, or if I give it a ton of json to analyse, it will fail, even if it’s stringified.

Note this only happens with the system message.

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

Hi @Wayne

You should be able to escape this by using double curly braces.

So in your case:

{{
“name”: “John Doe”,
“age”: 30
}}

Hi Ria,

This isn’t what I’m mean, I don’t think, lets say I want to give an AI Agent an and example json structure, it won’t allow { } as it thinks this is a placeholder for something, and if I use {{ }}, it think I’m going to write an expression.

So I have no way to give it a json exmaple.

The only workaround I’ve found is to use the memory manager to insert the system message as it won’t work in the AI Agent node when adding a system message.

Hi @Wayne,

Not knowing what your exact use case is, but perhaps you could use two agents (either chained or use the sub-workflow tool) to have the other agent do the structuring with the Output Parser Node ?

Otherwise, feel free to raise this as a feature request here: Feature Requests - n8n Community

The issues I’m having is the structured output parser is failing, to I want to give it my own prompt which i know work, but I need to specify the json I want with an example in the system message, but it wont let me.

I also want to provide dynamic json data in the system message, but again, it won’t allow it.

Hi Wayne,

I’d also suggest a tools agent, which has much better support for output parsing. But as Ria said, if you want to use JSON in system messages for a Conversational agent, you’d need to escape curly brackets so something like:

{{ $json.toJsonString().replaceAll('{', '{{').replaceAll('}', '}\}') }}

If you’d use a tools agent, you can just insert JSON directly:

Here’s a small workflow showing both approaches:

Hope that helps!

Oleg

3 Likes

Ahh thanks! I didn’t realise it worked in a tool agents but not a convo agent! Good to know, thanks for the info Oleg :slight_smile:

1 Like

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