Requesting JSON Output from ChatGPT / Escaping curly braces

Describe the problem/error/question

I am trying the new AI Beta locally

My aim is to classify input and get a JSON structure out of it.

I figured out, that the AI node already predefines a quite elaborate prompt to get JSON output in such a format:

{ “action”: “Final Answer”, “action_input”: <the actual output" }

I don’t need tools, so actually I would be fine with a plain JSON output to my question

I tried to manipulate the prompts, but ran into different problems.

My idea was to specify the JSON output I want to the LLM, but I need to escape the curly braces.

I found this idea: Escape brackets

but when I use the following plain input (not an expression)

Please Use the following JSON Format

{{ '{' }}
   "action": "Final Answer",
   "action_input": {{ '{' }}
      "classification": "your classification result";
   {{ '}' }}
{{ '}' }}

What is the error message (if any)?

I am getting

Problem in node ‘Agent‘

Single ‘}’ in template.

So it looks like the escaping is not working?

Additional question

The N8N Engine tries to check for this action_input JSON and retry the LLM call - can I disable this check and check the output for myself?

Information on your n8n setup

Hi @alexm, I’m not sure I fully understand the use-case. But if you’d want a JSON output from the agent or chain, the easiest way would be to use structured output parser and specify output schema. Check this simple example of extracting sentiment and array of verbs used in the text, the agent responds with a parsed JSON:

Using the output-parser has another advantage, it validates the output of LM, so you can be sure that it’s always correct and handle the path where it’s not.
Here’s the example WF:

I’m not exactly sure what happened in your WF, it would help if you could share the full workflow to better understand the issue.


Okay, I was using a very wrong approach, that works pretty well, still the GPT3.5 model sometimes needs some iterations, but that should be okay. Thank you very much.

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