Skip to content
AI agent outputs in...
 
Notifications
Clear all

AI agent outputs incorrect format when using a tool

12 Posts
7 Users
0 Reactions
6 Views
Ares_Sanchez
(@ares_sanchez)
Posts: 4
Active Member
Topic starter
 

Hi everyone,

I'm working on creating an agent that can search my website for information before responding to a chat. The problem I'm encountering is that the agent isn't using the correct JSON format for the tool, and I'm having trouble pinpointing the reason.

I need the agent to produce the following output:

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

However, it's currently using the tool with this format instead:

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

I observed this issue while reviewing the action logs, where this text 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:

{"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 suspect this is what's causing the interference with my intended output, but I'm unsure about the source of this text.

I'd like to share my workflow, but I'm not sure of the best way to do so.

Any assistance would be greatly appreciated.

 
Posted : 27/02/2025 9:14 am
n8n
 n8n
(@n8n)
Posts: 97
Trusted Member
 

It seems your topic is missing some crucial details. Could you please provide the following information, if relevant?

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

Please share these details to help us assist you better.

 
Posted : 27/02/2025 9:16 am
Daniel_Lamphere
(@daniel_lamphere)
Posts: 9
Active Member
 

In the top right corner of your workflow, click the three dots and then select 'download'. Subsequently, copy and paste the content into a preformatted text box: </>

 
Posted : 27/02/2025 9:27 am
Ares_Sanchez
(@ares_sanchez)
Posts: 4
Active Member
Topic starter
 

Thank you! The workflow is attached.

 
Posted : 27/02/2025 9:50 am
Daniel_Lamphere
(@daniel_lamphere)
Posts: 9
Active Member
 

Consider using this node for the output parser:

 
Posted : 27/02/2025 9:58 am
Ventsislav_Minev
(@ventsislav_minev)
Posts: 8
Active Member
 

You're seeing this added to the prompt because you likely enabled the ‘Require specific output format’ toggle in the agent node settings and attached a structured parser with example JSON.

image

This action generates the actual JSON schema and passes it at the end of the prompt.

If you've configured this, the simplest approach is to be more specific in your prompt, instructing it like so:
Output <this information> into <this attribute>.
In the example, you can also format it like this:
{"summary":"summary of the email goes here"}

However, relying solely on the AI for accurate formatting can be risky and isn't guaranteed.
To improve the chances of success, you can:

  1. Add an autofixing parser
  2. Enable Retry on Fail
  3. Enable branching on error and attempt to process the string with another AI node.

I've encountered the same issue frequently. The most effective approach I've found is to have one AI generate the text without a specific format, and then have a second AI node format it into JSON. This way, each agent has a single responsibility, increasing the likelihood of success. (You can also incorporate retries and error branching.)

 
Posted : 27/02/2025 10:17 am
Ares_Sanchez
(@ares_sanchez)
Posts: 4
Active Member
Topic starter
 

Appreciate you all looking into this.

Following your suggestion, I'm encountering a new error:

This is happening because the format is still incorrect for what the sub-workflow input expects. My understanding is that the output parser is intended for the model's response, not for the tool's call. Is that accurate?

Thank you for the advice. I do not have "Required specific output" enabled for the agent. I also understand your point about separating the steps, but in this particular case, it's not feasible as the issue occurs between the agent and the tool call, which does not allow for any intermediaries.

 
Posted : 27/02/2025 11:29 am
Ventsislav_Minev
(@ventsislav_minev)
Posts: 8
Active Member
 

I understand. It's considerably more challenging with tools.

Yes, the output parser is intended for the output of the AI Agent node, not for tool calls.

Regarding the error you're encountering, this frequently occurs when the AI generates characters that disrupt the JSON syntax. It often wraps code with json or markdown.

You can include instructions in the prompt to avoid this, but it still happens.
I haven't discovered a method to prevent it entirely, so I send myself a message and correct it manually.

:expressionless:

 
Posted : 27/02/2025 11:40 am
Ares_Sanchez
(@ares_sanchez)
Posts: 4
Active Member
Topic starter
 

I'm having a lot of trouble figuring this out and have spent the whole day trying to make it work without success. Does anyone have any advice on how to get this functioning? Could the problem be that I'm attempting to pass two keys to the tool, rather than the default "query" that the model typically uses?

 
Posted : 27/02/2025 1:37 pm
Chris7935
(@chris7935)
Posts: 1
New Member
 

I'm experiencing a comparable problem.
The tool operates as a distinct workflow, and its JSON output is accurate.
Is there a way to bypass the second AI model iteration once the output has been correctly generated, and simply return that?

 
Posted : 01/03/2025 2:48 pm
faber
(@faber)
Posts: 1
New Member
 

Hello everyone, I also explored this forum to address a formatting issue I encountered, but the structured output approach didn't yield the best results for me.

Ultimately, I implemented a solution using the information extractor node. While it requires some adjustments to meet specific needs, this method proved very effective for my use case.

 
Posted : 09/05/2025 7:42 pm
Urs_Stettler
(@urs_stettler)
Posts: 1
New Member
 

I've been facing this issue for an entire week.

  • The AI agent wraps its output into JSON, Markdown, or stringifies JSON into a string.
  • This happens inconsistently.
  • It doesn't integrate well with tools.
  • Tool outputs are also returned to the AI agent in a jumbled state.
  • Occasionally, callin.io complains about schema mismatches.
  • These schemas cannot be modified.
  • Sometimes the output is labeled 'output', then 'text', then 'response', or 'output' nested within 'response', or something else entirely.

This situation cannot be reliably managed. I attempted to process the AI agent's output using a parsing code node but was constantly surprised by the various ways the agent managed to bypass any parser. Furthermore, the parser doesn't assist with tool calls. This includes differences between sub-workflows used as tools and MCP clients that connect to an MCP server with sub-workflows attached as tools. The concept of enabling communication between all these components is excellent, but a significant overhaul of the communication methods between these parties is necessary.

From my perspective, I've been outmaneuvered to the extent that I believe the complexity of each AI agent must be kept very minimal. We should instead run a larger number of AI agents, with extensive data refinement processes between them to manage the information flow.

 
Posted : 17/07/2025 4:43 pm
Share: