AutomationFlowsAI & RAG › Query Postgresql Database with Natural Language Using Groq AI Chatbot

Query Postgresql Database with Natural Language Using Groq AI Chatbot

ByGegenfeld @gegenfeld on n8n.io

This guide shows you how to deploy a chatbot that lets you query your PostgreSQL database using natural language. You will build a system that accepts chat messages, retains conversation history, constructs dynamic SQL queries, and returns responses generated by an AI model. By…

Chat trigger trigger★★★☆☆ complexityAI-powered11 nodesChat TriggerMemory Buffer WindowAgentGroq ChatPostgres Tool
AI & RAG Trigger: Chat trigger Nodes: 11 Complexity: ★★★☆☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #3680 — we link there as the canonical source.

This workflow follows the Agent → Chat Trigger recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "ow1aBANn8lQH0TbA",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "My workflow 4",
  "tags": [],
  "nodes": [
    {
      "id": "3be32b55-6c92-45e3-805f-3c582f6bb237",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        760,
        320
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "c0685ca7-91bd-4177-848d-ea7f3a4c160f",
      "name": "Chat History",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1100,
        520
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "b2e6112c-451e-434f-a732-4c469721f364",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1180,
        320
      ],
      "parameters": {},
      "typeVersion": 1.7
    },
    {
      "id": "52a55d14-7a46-43fb-9f8c-5fdd099cc4b8",
      "name": "Groq Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "position": [
        920,
        520
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "d9ff0f6e-e08d-49bc-bd29-1a6602b1562e",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        880,
        700
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "56b21c24-9a74-4f61-ad03-2e6c892350d6",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1060,
        700
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "63a28a91-68e3-45a5-b236-559db54f87b7",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1240,
        700
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "b6dad064-7699-4f07-99c5-cca3a5f3bb82",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        760,
        100
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "36b9bf75-cb1d-45ed-8e01-99c272580fae",
      "name": "PostgreSQL Schema",
      "type": "n8n-nodes-base.postgresTool",
      "position": [
        1480,
        520
      ],
      "parameters": {},
      "typeVersion": 2.5
    },
    {
      "id": "71f57073-6857-4b7f-9ee9-e1dc3ce250c5",
      "name": "PostgreSQL Definition",
      "type": "n8n-nodes-base.postgresTool",
      "position": [
        1660,
        520
      ],
      "parameters": {},
      "typeVersion": 2.5
    },
    {
      "id": "95e64a15-03c5-44d9-9a33-4cbd392ab008",
      "name": "PostgreSQL",
      "type": "n8n-nodes-base.postgresTool",
      "position": [
        1280,
        520
      ],
      "parameters": {},
      "typeVersion": 2.5
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "59656397-0d25-47f3-94f3-c00beb3bf8d8",
  "connections": {
    "PostgreSQL": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Chat History": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Groq Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "PostgreSQL Schema": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "PostgreSQL Definition": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This guide shows you how to deploy a chatbot that lets you query your PostgreSQL database using natural language. You will build a system that accepts chat messages, retains conversation history, constructs dynamic SQL queries, and returns responses generated by an AI model. By…

Source: https://n8n.io/workflows/3680/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

teste. Uses chatTrigger, agent, lmChatGroq, memoryBufferWindow. Chat trigger; 24 nodes.

Chat Trigger, Agent, Groq Chat +7
AI & RAG

pix-zap. Uses chatTrigger, agent, toolCalculator, toolWikipedia. Chat trigger; 21 nodes.

Chat Trigger, Agent, Tool Calculator +7
AI & RAG

This workflow enables multimodal file analysis using Google Gemini tools connected to a text-only LLM agent. Users can upload images, videos, audio files, or documents via a chat interface. The workfl

Agent, Google Gemini Tool, Chat Trigger +3
AI & RAG

📌 Overview This workflow automates end-to-end appointment scheduling for your business using an AI-powered chatbot. Clients can book, reschedule, or cancel meetings through a simple chat interface — n

Chat Trigger, Agent, Groq Chat +6
AI & RAG

Becomex v2. Uses chatTrigger, lmChatOllama, agent, toolWorkflow. Chat trigger; 17 nodes.

Chat Trigger, Ollama Chat, Agent +9