When creating workflows in [email protected] using the OpenAI Chat Model node, there is a very lower probability that the multi-turn conversation interface may return a JSON body regarding to the tool_calls

Describe the problem

From n8n workflow execution, there’s not any error prompt, but the WhatsApp (My bot frontend) will return a JSON body that shown in the screenshot below in extremely rare cases.

What is the error message (if any)?

json {“route”:“billing”}
Please noted that route is the key word to change to the agent defined as billing.

“functionrouter_switch
json{“route”:“billing”}”
Please noted that function is the key word of tool_calls that called router_switch

Please share your workflow

I cannot share the detailed workflow, but in a simple way, I use Agent node and OpenAI Chat LLM node to invoke self-hosting DeepSeek V3-0324, all others are the tools to invoke the self-defined tool_calls, actually I’ve defined 3 Agents within all the workflows, and the System Prompt will ask LLM to decide which Agents will be called according to user inputs.

Share the output returned by the last node

[
{
“output”: “functionrouter_switch\njson\n{\"route\":\"billing\"}\n\n”,
“intermediateSteps”:
}
]

Information on your n8n setup

  • **n8n version: [email protected]
  • **Database: default: SQLite
  • **n8n EXECUTIONS_PROCESS setting: own
  • **Running n8n via Docker compose
  • **Operating system: Ubuntu 24.04 TLS
7 Likes

Hi there, i think you can modify your AI Agent prompt to never output the JSON return from a tool, add something like

never output tool call details or internal routing JSON in the final response. Only return human-readable replies unless explicitly instructed to output tool calls for routing purposes. All routing logic is handled silently.

of course modify it to suite your needs

1 Like

Thanks @fahmiiireza for the kindly feedback, very appreciated even during the weekend.

I have the same idea with you and gonner to try, but what do you think the root cause of this? I’m still struggling to see why cause this. Thanks Sir.

1 Like

may i see your workflow, to be sure?

do you turn on return intermetiate steps in your ai agent? if yes then you definitely want to turn it off

1 Like

Hi @fahmiiireza thanks for always kindly support.

For the detailed workflow I will try to get the full one exported as json, but I cannot share here by public access, if you can send me your Email that will be appreciated, thanks!

Yes, the Agent node had opened intermediate steps like this:

The purpose of intermediate steps is to ask agent to receive user inputs, and deliver to LLM, ask LLM to decide which agent need to go, and Agent node will deliver to the specific agent accordingly. It’s mandatory to open this feature as we need it to do dynamic decision making. Is it will cause this issue?

Yeah, intermediate steps is definitely what cause the AI to output the kind of JSON you are facing, because that is the full purpose of intermediate steps, to return all steps that the AI has taken, i usually only turn this on upon testing

but if you do need it then i guess we defiinitely need to exclude it somehow before going into the end user, one of the solution is like what i said above, to update the system prompt

the other solution would be to add a basic LLM chain node, or another AI Agent node, that is function to basically read the response and to check if it is human readable or no and if its not then do something else or just stop, depending on what youre trying to achieve

1 Like

Very appreciated for your kindly response @fahmiiireza

Emm, now we have two solutions to sort it out, I will try system prompt first of all.

Strange that the issue is happened on DeepSeek V3-0324 as LLM node but never ever happened before on GPT-4o or GPT-4.1 Not sure why.

Yeah, usually, the json response would be

{
“output”: “This is the message from AI”,
“intermediateSteps”: “and this is the intermediate step”
}

But every LLM have different way to handle how tp output the intermediate step

1 Like

Much appreciated for your kindly support! @fahmiiireza I will add system prompt and try to see the output, thanks!

1 Like

Lemme know the result, and always glad to help mate!

1 Like

Will definitely do so, Sir!

1 Like

Hi @fahmiiireza Hope you’re still doing good.

Hereby after adding the System Prompt like this, it will definitely get original error, looks like only when Change Agent which dynamically decide by intermediate steps.

look below frontend screenshots:

both null and the json body are unexpected outputs.

Hereby my System Prompt, for reference:

Function Call Handling

When executing function calls, strictly adhere to these protocols:

  1. Function Call Execution Protocol

    • Always execute function calls programmatically.
    • Never return raw function names or JSON bodies as text outputs.
    • Never output tool call details or internal routing JSON in the final response. Only return human-readable replies unless explicitly instructed to output tool calls for routing purposes. All routing logic is handled silently.
    • Invalid output example (PROHIBITED):
      "output": "functionrouter_switch\n\``json\n{"route":"billing"}\n```\n"`
  2. Retry Mechanism Requirements

    • If a function call fails due to network errors, timeouts, or execution failures:
      ✓ Immediately retry the identical function call
      ✓ Maintain original arguments and parameters
      ✓ Continue retrying until successful execution
    • Do NOT return error messages or intermediate states to the user during retries
  3. Critical Constraints

    • Never expose internal function signatures or JSON structures
    • Retry logic must be completely transparent to end-users
    • Prioritize atomic execution over diagnostic messaging

Compliance Validation
All outputs will be monitored for prohibited patterns. Non-compliant responses will trigger automatic regeneration.

Hi n8n supporters, is there anybody can help on this? Thanks!

I was curious, why not make a multi AI Agent workflow if you want it to change agents for every occasion

Hi @fahmiiireza Thanks for kindly response, is the multi-agent will be the only way to sort out?

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