How to access data for AI

Hi guy

I have prompted my AI agent to reciew the data from the Input field (it comes in jason, based on two different sheets)

I want to analyse the two data set and create a new spread sheet.

When i prompt the AI agent it just say "“Thank you for your instructions!\n\nTo proceed, please provide me with the input data”

The input data is litterally there. What am i doing wrong, so it’s not just saying “i understand what you want” but are actually excetuting it?


Hi Frederik!

I can see some issues in your User message. First, it didn’t add the INPUT information to your User message, so the AI does not know what you’re talking about, that’s why it’s replying, answering for the information.

You should create a User message where you add the input info, something like this:

Begin your generation, using the input information below:

{{ $json.output }}

Note: This is the output of your Merge1, so just click the field with the mouse and drag it to the User Message
—-------------

You also should inform the Model what is the definition of the input, so you should add at least the JSON fields the model would receive.
I’ll suggest you to add a System message and on the system message add all the basic instructions, input definition and tools used.

About tools, when you said “You have access to Google Sheets”. This instruction can be confused to the model, the best practices when using tools is to instruct the model to use the tool to access the Google Sheet, like this:

# Tools
- Google Sheet: Use this tool to access the Google Sheets with the information of…

Hope that helps!

Let me know if you have any other question, all the best!

1 Like

Thank you, I think im getting closer for it to work.

Sorry this is in danish language, but why will some of it not work “red” when i drag it from the input area and some of it will?

Like I got two differente things in the input i want to compare with each other and change the output.

Like the data from the “unmatched” file he shows green when i pull it in,
But the data from the “all data” as I called it, will show red

Hi Frederik

The problem is because of the previous Merge Node.
Your data structure shows unmatched and allData, probably coming from separate branches. When you use a Merge Node, only the current item’s root $json is available — not both full branches unless they were properly merged.

You can explicitly reference data from both inputs like this:

{{ $input[0].json.unmatched[0][“beløb”] }}
{{ $input[0].json.unmatched[0][“Konto nummer”] }}
{{ $input[0].json.unmatched[0][“navn”] }}

AND

{{ $input[1].json.allData[0].Kontonummer }}
{{ $input[1].json.allData[0].match }}
This avoids red expressions because it pins the reference to the correct input.

Please, let me know if that helps!

All the best!

I really need all data not just the 1 line [0].
I am really stucked here how to merge is prober before. If i even should merge it.

If I keep getting back that it cannot read it. Can you see what is wrong with this one?

Morning Frederik!

I see the problem, the issue is that {{ $json.unmatched.toJsonString() }} is not deeply serializing the objects, so the AI sees: [object Object], [object Object], …

This happens because toJsonString() doesn’t deeply expand nested arrays/objects unless they’re properly structured.

To pass a readable JSON array into the AI Agent, use the stringify() function instead, like this:
{{ JSON.stringify($json.unmatched, null, 2) }}


Other issue I saw in your screenshot is you’re using the INPUT information in both the USER and SYSTEM prompt. It doesn’t make much sense to send the input twice.
Just as a recap, the SYSTEM prompt should have the instructions to the model and the USER prompt the INPUT.

Also, there are many ways to merge the information on the Merge Node, take a look on the node documentation and see if the merge option you choose is the best option for your user case.
Merge Docs: Merge | n8n Docs

All the best!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.