# AI agent outputs in the wrong format when using a tool

**URL:** <https://community.n8n.io/t/ai-agent-outputs-in-the-wrong-format-when-using-a-tool/82418>\
**Category:** Questions\
**Created:** [February 27, 2025, 9:14am UTC](https://community.n8n.io/t/ai-agent-outputs-in-the-wrong-format-when-using-a-tool/82418 "2025-02-27T09:14:51Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ares\_Sanchez](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ares_sanchez/32/61111_2.png) [@Ares\_Sanchez](https://community.n8n.io/u/Ares_Sanchez)\
**Post date:** [February 27, 2025, 9:14am UTC](https://community.n8n.io/t/ai-agent-outputs-in-the-wrong-format-when-using-a-tool/82418/1 "2025-02-27T09:14:51Z")

</div>

Hey guys,

I am trying to build an agent that search in my website for information before replying a chat. The issue I am having is that the agent is not using the correct JSON format for the tool, and I can’t figure out why.

I need the agent to output this:

```json
{
  "term": "multi coin combo",
  "mode": ["feature_requests", "documentation"]
}

```

But instead is using the tool with this:

```auto
{
  "query": "{\"term\": \"multi coin combo\", \"mode\": [\"feature_requests\", \"documentation\"]}"
}

```

I noticed this looking through the action logs, which was automatically appended to my original query:

> Your output will be parsed and type-checked according to the provided schema instance, so make sure all fields in your output match the schema exactly and there are no trailing commas!
> 
> Here is the JSON Schema instance your output must adhere to. Include the enclosing markdown codeblock:
> 
> ```json
> {"type":"object","properties":{"output":{"type":"object","properties":{"query":{"type":"string"},"mode":{"type":"array","items":{"type":"string"}}},"additionalProperties":false}},"additionalProperties":false,"$schema":"http://json-schema.org/draft-07/schema#"}
> 
> ```

I think this is what interfering with my desired output, but I can’t figure out where is this text coming from.

I would like to share the workflow but not sure how to do it?

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![n8n](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/n8n/32/196425_2.png) [@n8n](https://community.n8n.io/u/n8n)\
**Post date:** [February 27, 2025, 9:16am UTC](https://community.n8n.io/t/ai-agent-outputs-in-the-wrong-format-when-using-a-tool/82418/2 "2025-02-27T09:16:17Z")

</div>

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:**

---

<div class="post-metadata">

**Author:** ![Daniel\_Lamphere](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/daniel_lamphere/32/39212_2.png) [@Daniel\_Lamphere](https://community.n8n.io/u/Daniel_Lamphere)\
**Post date:** [February 27, 2025, 9:27am UTC](https://community.n8n.io/t/ai-agent-outputs-in-the-wrong-format-when-using-a-tool/82418/3 "2025-02-27T09:27:55Z")

</div>

In the top right of your workflow, hit the 3 dots then download. Then copy paste the contents into a preformatted text box : \</\>

---

<div class="post-metadata">

**Author:** ![Ares\_Sanchez](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ares_sanchez/32/61111_2.png) [@Ares\_Sanchez](https://community.n8n.io/u/Ares_Sanchez)\
**Post date:** [February 27, 2025, 9:50am UTC](https://community.n8n.io/t/ai-agent-outputs-in-the-wrong-format-when-using-a-tool/82418/4 "2025-02-27T09:50:11Z")

</div>

Thanks! Attached the workflow.

---

<div class="post-metadata">

**Author:** ![Daniel\_Lamphere](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/daniel_lamphere/32/39212_2.png) [@Daniel\_Lamphere](https://community.n8n.io/u/Daniel_Lamphere)\
**Post date:** [February 27, 2025, 9:58am UTC](https://community.n8n.io/t/ai-agent-outputs-in-the-wrong-format-when-using-a-tool/82418/5 "2025-02-27T09:58:44Z")

</div>

Try this node for the output parser:

---

<div class="post-metadata">

**Author:** ![Ventsislav\_Minev](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ventsislav_minev/32/53540_2.png) [@Ventsislav\_Minev](https://community.n8n.io/u/Ventsislav_Minev)\
**Post date:** [February 27, 2025, 10:17am UTC](https://community.n8n.io/t/ai-agent-outputs-in-the-wrong-format-when-using-a-tool/82418/6 "2025-02-27T10:17:23Z")

</div>

You see this added to the prompt because you probably enabled the ‘Require specific output format’ toggle in the agent node settings and attached a structured parser with example JSON.  
 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/2/c/2ca507b8601ad4c495da9fe1766639cc86534e86.png)  
What this does is generate the actual JSON schema and pass it at the end of the prompt..

If you’ve done that the easiest thing you can try is to be more specific in your prompt and tell it things like:  
`Output <this information> into <this attribute>.`  
Also in the example you can do something like this  
`{"summary":"summary of the email goes here"}`

That said relying on the AI to do it properly is risky and not guaranteed to work.  
To improve chances of success you can:

1. Add an autofixing parser
2. Enable Retry on Fail
3. Enable branch off on error and try to process the string with another AI node.  
 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/d/5/d58d734c9e94dba148e0b64d2b08b218d7878cd8.png)

I have experienced the same problem a lot and the best result that i got were by having 1 AI generate the text without configuring specific format, and a second one that just formats it to json. This way each agent has 1 responsibility and is more likely to succeed. (You can add retries and error branch too)

---

<div class="post-metadata">

**Author:** ![Ares\_Sanchez](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ares_sanchez/32/61111_2.png) [@Ares\_Sanchez](https://community.n8n.io/u/Ares_Sanchez)\
**Post date:** [February 27, 2025, 11:29am UTC](https://community.n8n.io/t/ai-agent-outputs-in-the-wrong-format-when-using-a-tool/82418/7 "2025-02-27T11:29:17Z")

</div>

Thanks for looking into it guys.

@daniel_lamphere with your suggestion I am getting a new error:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/1/4/143a8d89d8a0fc565f9262c7cad091d255e7e51d.png)

This is because is not what the subworkflow input expects, it’s still using the wrong format. The output parser is for the response of the model, not for the call of the tool, is that correct?

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/5/b/5b5f16fc62b427b0b46a41c45301ab77674dc6ca.jpeg)

@Ventsislav_Minev

Thanks for the tips. I don’t have enabled “Required specific output” in the agent. Also I get what you mean by separating the steps but this I can’t separate because it’s between the agent and the tool call, which doesn’t accept any intermediaries.

---

<div class="post-metadata">

**Author:** ![Ventsislav\_Minev](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ventsislav_minev/32/53540_2.png) [@Ventsislav\_Minev](https://community.n8n.io/u/Ventsislav_Minev)\
**Post date:** [February 27, 2025, 11:40am UTC](https://community.n8n.io/t/ai-agent-outputs-in-the-wrong-format-when-using-a-tool/82418/8 "2025-02-27T11:40:41Z")

</div>

I see. With tools it’s much more difficult.  
Yes the output parser is for the output of the AI Agent node, not for tool calls.

As for the error you are getting, this often happens when the AI generates characters that break the json syntax. Very often it wraps code with `json `  
or `markdown`

You can add instructions to the prompt to not do that but it still happens.  
I haven’t found a way to prevent it completely so I send myself a message and fix it manually 😑

---

<div class="post-metadata">

**Author:** ![Ares\_Sanchez](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ares_sanchez/32/61111_2.png) [@Ares\_Sanchez](https://community.n8n.io/u/Ares_Sanchez)\
**Post date:** [February 27, 2025, 1:37pm UTC](https://community.n8n.io/t/ai-agent-outputs-in-the-wrong-format-when-using-a-tool/82418/9 "2025-02-27T13:37:31Z")

</div>

For the life of me I can’t figure this out, I’ve spent the entire day trying to make this work with no luck. Anyone here have tips on how to make it work? Is the issue that I am trying to pass two keys to the tool instead of the default “query” the model always use?

---

<div class="post-metadata">

**Author:** ![Chris7935](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@Chris7935](https://community.n8n.io/u/Chris7935)\
**Post date:** [March 1, 2025, 2:48pm UTC](https://community.n8n.io/t/ai-agent-outputs-in-the-wrong-format-when-using-a-tool/82418/10 "2025-03-01T14:48:09Z")

</div>

I’ve got a similar issue.  
The tool is a separate workflow and its JSON output is correct.  
Is it possible to circumvent the 2nd AI model round, after the output has already been created correctly, and just return that?

---

<div class="post-metadata">

**Author:** ![faber](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/faber/32/79562_2.png) [@faber](https://community.n8n.io/u/faber)\
**Post date:** [May 9, 2025, 7:42pm UTC](https://community.n8n.io/t/ai-agent-outputs-in-the-wrong-format-when-using-a-tool/82418/11 "2025-05-09T19:42:48Z")

</div>

Hey guys, I used this forum here to try to overcome the formatting issue as well, but the structured output solution did not work for me that well too.

What I did at the end was use the information extractor node. It needs some tweaks to get to the point you need, but the solution worked really well for me.

---

<div class="post-metadata">

**Author:** ![Urs\_Stettler](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/urs_stettler/32/77040_2.png) [@Urs\_Stettler](https://community.n8n.io/u/Urs_Stettler)\
**Post date:** [July 17, 2025, 4:43pm UTC](https://community.n8n.io/t/ai-agent-outputs-in-the-wrong-format-when-using-a-tool/82418/12 "2025-07-17T16:43:35Z")

</div>

I’ve been stuck on this problem for a whole week.

- ai agent wraps output into framing json, markdown, or stringifies json into a string.
- inconsistently
- does not play nice with tools
- tools output is just as messed up back to the ai agent
- from time to time n8n complains about not matching schemas.
- only these schemas can’t be influenced
- sometimes the output is called output, then text, then response or output nested in response or whatever.

This is not something that can be reliably dealt with. I tried to run the ai agent’s output through a parsing code node but kept getting surprised by the multitude of ways the agent manages to outmanoeuvre any parser. Plus the parser does not help for tool calls. Add differencies between subworkflows as tools and mcp clients that lead to an mcp server with subworkflows attached as tools. The idea of having all these parties talk to eachother is great, but there needs to be some kind of overhaul over the way communication happens between all these counterparties.

As far as I am concerned, I have been outmanoeuvred to the point that I believe at this point, complexity at each ai agent has to remain very very subdued and we need to run rather many ai agents with lots of straightening out the information in between them to sort of control the data.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [October 15, 2025, 4:44pm UTC](https://community.n8n.io/t/ai-agent-outputs-in-the-wrong-format-when-using-a-tool/82418/13 "2025-10-15T16:44:10Z")

</div>

Closed on October 15, 2025, 4:44pm UTC

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