I’m a complete noob with n8n, I’m just starting to use it now and it seems I’ve already run into a problem I can’t solve.
I’m trying to create a high-quality script automation and I’d like to follow this logic: create the script > send it to the validator > if true, follow the flow > if false > refiner. I think the problem is that I want to validate the text twice to have high quality. I’ve already done SEVERAL tests, inserting if, switch, etc., but either it gives an error if the parser fails or the code to control the number of refinements simply doesn’t work and the system gets stuck in an infinite loop.
Can some kind soul help me fix this bug? Does anyone have a working template that follows this logic without the information getting lost along the way?
I spent the WHOLE day trying to get help from ChatGpt, but it kept making me test the same errors until I lost my daily credits.
Hey can you share a screenshot of your workflow and the actual error message youre getting? Hard to tell whats going wrong without seeing how the nodes are connected and what the output parser is returning.
I also tried something like that with the parsers in the agents, either the output parsers give an error, or the circuit gets stuck in an infinite loop.
In both cases, the same obstacle persisted.
the output parser issue is usually the model not returning the format it expects consistently — not all models support structured output reliably for validation loops like this, ive had this with smaller/cheaper models before. for the infinite loop, add a counter that increments each cycle and stop after 3 tries — that way broken logic has a ceiling and you can see which pass failed. what model are you using in the validator agent?
Actually, I already have some code with that JavaScript, which is intended to control the refinements; I believe it does the counting you mentioned. And the model I’m using in the validator agent is gemini-2.5-flash.
Hi @lasher_u Welcome!
I think the issue is related to how the AI agents output the data as you are straightaway using that with a merge, consider trying the Auto Fix Output Parser i know it is deprecated but you can still use. I think you need to work on your overall flow too, it is a bit hard to debug with all the code nodes, you can try using a Set Fields node also. (share your JSON)
gemini 2.5 flash does support structured output, so if the parser keeps failing it’s likely the output schema definition not matching what the model actually returns — tightening that up usually fixes it. your counter code looks fine btw, the logic is solid.
anshul’s auto-fix suggestion is a good fallback if you want to skip the schema tweaking for now.