I have a list of URLs in a csv file that I need to load into memory, audit and push the results out to a report file.
My current flow grabs each URL and loads the file into memory, then it passes the data to a Basic LLM Chain node as part of a prompt, once the prompt is answered the results are saved to a txt file.
Currently, all the results are appended to the same txt file, which means I then need to go and manually split the file into the respective script responses and save them out to individual files (as I need to pass them through the LLM again and if I do that with the appended report, it is too large for the context window).
So I have implemented a Loop Over Items node so that I can write the LLM response to a new file each time it iterates. This would give me many files (one for each response) which is what I want.
The problem I am facing is how to name the files based on the script name?
If I try to set a variable (before or during the Loop Over Items node) and then use that variable for the filename it works fine for the first iteration but then fails on subsequent iterations with the following error:
Expression info invalid
An expression here won't work because it uses `.item` and n8n can't figure out the [matching item](https://docs.n8n.io/data/data-mapping/data-item-linking/item-linking-errors/). This is because the node **'Basic LLM Chain'** returned incorrect matching information (for item 0 of run 0).
Try using `.first()`, `.last()` or `.all()[index]` instead of `.item`.
But the problem is there has to be some context between the filename and the script that the report relates too (otherwise we have no way of knowing what response belongs to what script).
So how can I find the index that is currently iterating in the For loop so I can reference it by .all()[index] or is there some way to do this that is escaping me?
Information on your n8n setup
- n8n version: 1.61.0
- Database (default: SQLite): SQLite
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app): npm
- Operating system: MacOS