Help with splitting ai output into separate items

Problem?

I want to be able to separate each ‘scene’ from my story as a separate item output in n8n. The reason I want to do this is so that I can have each scene act as a prompt to generate AI images.

I have tried some stuff, but I’m new so I don’t understand how to do it properly.

This is the output from Google Gemini. As you can see, I want each scene to be outputed as a separate item.

This is my workflow.

This is my AI prompt

Can Some please help me out? I am a beginner :grimacing:

Hi there @Manvan welcome to the community

In order to make the output of an AI Agent to comeout structured in n8n is you can use a Structured output parser

you can refer this video on how to use it

and the official documentation

it’s basically just a way to say to the AI that you want the output to be parsed the way you define it in the output parses

hope it helps

Hey @Manvan !

Welcome to n8n community!

Ok, so your “output” from ai agent node (in my case I set “Out” instead output).

I would use a Code node in order to “break up” the text you get as response:

An as you can see in logs :

I had a text with multiple “SCENE” words in that output, and at the end I see 3 items.

Or as @fahmiiireza suggested as well!

Cheers!

Hello, I think your method works. I came across this video on YouTube before but I don’t know how to use this for my situation. Could you help me further? :thinking: