Query n8n Credentials with AI SQL Agent n8n Workflow Template

n8n workflow template · 9 nodes · OpenAI

Query n8n Credentials with AI SQL Agent is a free n8n workflow template that starts when a chat message is received and works with OpenAI and n8n API. It has 9 nodes, 5 of them AI nodes (Chat Trigger, Code Tool, OpenAI Chat Model and Window Buffer Memory). The notes inside the workflow say: “Instead of building a form interface like a regular person, we'll just use an AI tools agent who is given aaccess to perform queries on our database. You can ask it things like "which workflows are using slack + airtable + googlesheets?"” To run it, you add your own credentials for OpenAI API and n8n API.

At a glance

Trigger
Chat Trigger (Chat Trigger)
Nodes
9
Apps
OpenAI and n8n API
AI nodes
5
Credentials
2 types
Category
IT, security and DevOps

Apps and integrations

  • OpenAI
  • n8n API

Node types used

  • Manual Trigger
  • Edit Fields (Set)
  • Code
  • Chat Trigger
  • Code Tool
  • OpenAI Chat Model
  • Window Buffer Memory
  • AI Agent
  • n8n

How it works

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

Step 2. Use Agent as Search Interface

Instead of building a form interface like a regular person, we'll just use an AI tools agent who is given aaccess to perform queries on our database. You can ask it things like "which workflows are using slack + airtable + googlesheets?"

Setup notes

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

Try It Out!

This workflow let's you query workflow credentials using an AI SQL agent. Example use-case could be

  • "Which workflows are using Slack and Google Calendar?"
  • "Which workflows have AI in their name but are not using openAI?"

Run the Steps separately!

  • Step 1 populates a local database
  • Step 2 engages with the chatbot

Step 1. Store Workflows Credential Mappings to Database

We'll achieve this by querying n8n's built-in API to query all workflows, extract the credentials list from the nodes within and then store them in a SQLite database. Don't worry, the actual credential data won't be exposed! For the database, we'll abuse the fact that the code node is able to create Sqlite databases - however, this is created in memory and will be wiped if the n8n instance is restarted.

Required

You'll need an n8n API key. Note: available workflows will be scoped to your key.

Nodes in this workflow

The 9 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:

  1. When clicking "Test workflow" (Manual Trigger)
  2. Map Workflows & Credentials (Edit Fields (Set))
  3. Save to Database (Code)
  4. Chat Trigger (Chat Trigger)
  5. Query Workflow Credentials Database (Code Tool)
  6. OpenAI Chat Model (OpenAI Chat Model)
  7. Window Buffer Memory (Window Buffer Memory)
  8. Workflow Credentials Helper Agent (AI Agent)
  9. n8n (n8n)

Credentials you need

  • OpenAI API – used by OpenAI Chat Model
  • n8n API – used by n8n

Configure your own credentials after importing. Create each credential in n8n, then select it in the node.

How to import into n8n

  1. Download the JSON file with the button above.
  2. In n8n, open a new workflow, select the ... menu and choose Import from File. You can also paste the JSON straight into the editor canvas.
  3. Open each node that shows a warning and select or create its credential.
  4. Read the notes on the canvas, test the workflow with sample data, then activate it.

Do you need somewhere to run it? Read our guide to self-hosted n8n.

Need this customised?

We can adapt this workflow to your apps, data and process, then deploy and support it.

Contact Us