Hi everyone,
I'm using the AI Agent node in n8n. My goal is to have it process data and output a structured JSON array directly, containing fields like Category, keyword, Reasoning, MSV, etc.
To ensure the output format, I have a Structured Output Parser node connected downstream from the AI Agent. The parser is configured with a JSON example that perfectly matches the structure I want the AI Agent to output.
The Problem:
The AI Agent node doesn't seem to strictly follow my prompt instructions. Even though I explicitly instruct it in the prompt to output ONLY the JSON array and nothing else, it frequently prepends conversational text (e.g., "Okay, I will start processing..." or similar phrases) before starting the actual JSON ([).
This prefix text causes the downstream Structured Output Parser to fail immediately with the error: Model output doesn't fit required format.
What I've Tried:
- In the AI Agent prompt, I've detailed the task, provided an exact JSON structure example, and used very strong instructions explicitly forbidding any confirmation messages, comments, or conversational text, demanding the response start directly with [ and end with ].
- I've double-checked that the JSON example in the Structured Output Parser is correct and perfectly matches the structure requested in the prompt.
- I've reviewed the AI Agent node's settings but couldn't find any obvious option to disable this "conversational" behavior.
My Questions:
- Are there any prompt engineering tricks specifically effective for the n8n AI Agent node to make it more reliably obey commands and output only pure JSON without any prefix?
- Does the AI Agent node itself have any specific configuration settings or modes I might have missed that could enforce raw data output instead of simulating dialogue? (I've looked through the settings but found nothing obvious).
- If forcing the AI Agent to behave is unreliable, are there recommended n8n workflow designs or alternative nodes to perhaps clean up the AI's output (remove the prefix text) before it reaches the Structured Output Parser?
This behavior is quite frustrating as it makes the AI Agent node feel unreliable for structured data tasks. Any advice on how to get stable, pure JSON output from the AI Agent would be greatly appreciated!
Thanks!