Templates / Natural language database queries with dual-agent AI & PostgreSQL integration

Natural language database queries with dual-agent AI & PostgreSQL integration

Ready for 3.0

by Paul βœ“ Β· 9,801 views Β· created 2025-06-17 Β· Engineering, AI RAG

Ready for 3.0. This template uses no nodes that n8n 3.0 removes. No removed nodes, versions or helpers found. Static check, last run 2026-10-19.

Nodes used (13)

AI AgentThinkOpenRouter Chat ModelPostgres Chat MemoryTelegramOpenAICall n8n WorkflowPostgres

What it does

AI Database Assistant with Smart Query's & PostgreSQL Integration Description: πŸš€ Transform Your Database into an Intelligent AI Assistant This workflow creates a smart database assistant that safely handles natural language queries without crashing your system. Features dual-agent architecture with built-in query limits and PostgreSQL optimization – perfect for commercial applications! βœ… Ideal for: SaaS developers building database search features πŸ” Database administrators providing safe AI access πŸ›‘οΈ Business teams needing user-friendly data queries πŸ“Š Anyone wanting ChatGPT-like database interaction πŸ€– πŸ”§ How It Works 1️⃣ User asks a question – "Show me top 10 popular products" 2️⃣ Main AI Agent – Interprets the request and ensures safety limits 3️⃣ SQL Sub-Agent – Generates precise PostgreSQL queries 4️⃣ Database executes – Returns formatted, limited results safely ⚑ Setup Instructions 1️⃣ Prepare Your Database Ensure PostgreSQL is accessible from n8n Note your table structure and column names Set up database connection credentials 2️⃣ Customize the Templates Replace YOURTABLENAME with your actual table name Update YOURFIELDS with your column names Modify examples to match your use case Important: Keep all LIMIT clauses intact! 3️⃣ Configure the Agents Copy Main Agent system message to your primary AI node Copy Sub-Agent system message to your SQL generator node Connect the sub-workflow between both agents 4️⃣ Test & Deploy Test with sample queries like "Show me 5 recent items" Verify query limits work (max 50 results) Deploy and monitor performance 🎯 Why Use This Workflow? βœ”οΈ System Protection – Built-in limits prevent crashes from large queries βœ”οΈ Natural Language – Users ask questions in plain English βœ”οΈ Commercial Ready – Generic templates work with any database βœ”οΈ Dual-Agent Safety – Smart interpretation + precise SQL generation βœ”οΈ PostgreSQL Optimized – Handles complex schemas and data types 🚨 Critical Features Query Limits: Default 10, maximum 50 results (can be modified) Error Prevention: No unlimited data retrieval Smart Routing: Natural language β†’ Safe SQL β†’ Formatted results Customizable: Works with any PostgreSQL database schema πŸ”— Start building your AI database assistant today – safe, smart, and scalable!

View the original on n8n.io β†’ Check your own copy

Get the weekly β€œwhat broke” email

New templates, newly broken ones, and n8n release changes. One short email a week.

Form not loading? Subscribe here.