Pass dynamic perameters to postgres_SQL node query

hi i am new to n8n basically i have build a chat bot, which is created query on the base of question, but sometime AI based queries are failed to give accurate result, so i have created sql function in vector database, then i wanted to get result from that sql function
for example i have created a sql function “compare_project(project1_id, project2_id)” so when chat bot asked to compare about 2 project first i want to fetch id of project from database query then i want to add that project_id to posgresSQl query.
the problem is i am unable to pass dynamic data to this query.

Hey! You can click the :sparkles: button next to the Query Parameters to let the AI decide this. Also, you can manually specify after you switch the box to Expression and type this:

{{$fromAI('projectId1')}}, {{$fromAI('projectId2')}}

This is detailed here:

Please mark this as Solution if it helped :slight_smile:

no, it’s not working. AI is not handling. what if i wanted to pass dynamic perameters which should fetch from chat? how it would possible in n8n?

Hm, what if you try with a better description, something like:

{{$fromAI('project1ID', 'ID of the 1st project to compare')}},{{$fromAI('project2ID', 'ID of the 2nd project to compare')}}

What happens exactly? Is the AI using the tool at all? Can you see what values it uses?

Alternatively, you could do something like this, to first obtain the 2 values and reference them in the Parameters later:

sorry for late reply, yes you are right but i need an information extractor between AI agent and compare projects node. how is it possible? below screenshot can help you to understand

No, you insert the information extractor before the AI node, then in the Tool, you can use the values like so:

{{$('Information Extractor').item.json.output.project1_id}}, {{$('Information Extractor').item.json.output.project2_id}}
1 Like

thanks i understand, it’s look like to difficult to make rules for get the project A and project B name, coz in chat bot user can be ask comparison question in different ways, like i want to compare projectA with projectB, could you compare projectA budget with projectB? what is the best way to handle this scenario?

The extractor node uses AI and you can provide a prompt there too, so that would be the best way to go about it - it should be able to pick up the IDs in various different user prompts.

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