Chat with Supabase using OpenAI and n8n AI Agent

Struggling to query your Supabase database without SQL knowledge? This n8n workflow harnesses OpenAI to create an AI agent that dynamically queries your PostgreSQL DB on Supabase, making data interaction easy and conversational.
chatTrigger
postgresTool
agent
+2
Workflow Identifier: 1544
NODES in Use: chatTrigger, lmChatOpenAi, postgresTool, agent, stickyNote
Automate Supabase queries with n8n and OpenAI

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What this workflow does

This workflow creates a chat-based AI agent that talks to a Supabase PostgreSQL database using natural language.

The AI reads user messages, writes SQL queries by itself, runs these queries in the database, then returns simple answers based on the results.

This solves the problem of needing to know SQL to get data fast. The user can ask questions in plain language and get answers right away.


Who should use this workflow

This is for people who want information from their database without writing SQL code.

It works well for product managers, business users, or anyone uncomfortable with databases but needs quick data answers.


Tools and services used

  • n8n: Automation platform to build and run the workflow.
  • Supabase PostgreSQL: Database where the data lives.
  • OpenAI API: GPT model to understand user questions and build SQL queries.

Beginner step-by-step: How to use this workflow in n8n

Step 1: Import the workflow

  1. Click the Download button to get the workflow file.
  2. In the n8n editor, click on “Import from File” and select the downloaded workflow.

Step 2: Add credentials and API keys

  1. Go to the Credentials section in n8n.
  2. Add a PostgreSQL credential using your Supabase database host, name, username, and password.
  3. Add an OpenAI API credential with your OpenAI API Key.

Step 3: Update workflow settings if needed

  1. Check nodes that run SQL queries and confirm table names and schema matches your database.
  2. Update any email addresses, channels, or webhook URLs in the workflow if you connect to other systems.

Step 4: Test the workflow

  1. Trigger the Webhook node by sending a test chat message.
  2. See if the AI agent responds with correct data from your database.

Step 5: Activate for production use

  1. Turn on the workflow switch to make it active.
  2. Monitor runs with n8n logs for any errors or problems.
  3. If running on your own server, consider using self-host n8n for better control.

How the workflow works: Inputs, processing, and outputs

Inputs

  • User sends a natural language question via chat or webhook.
  • The message text contains the user’s data request.

Processing steps

  • The AI Agent node uses OpenAI to read the request and create a SQL query.
  • The workflow runs the SQL query on Supabase PostgreSQL using configured Postgres nodes.
  • Queries include schema lookups to know table structures and columns for accuracy.
  • Results are gathered and analyzed by the AI to write user-friendly answers.

Outputs

  • The AI replies with simple text answering the user’s question.
  • Data is shown clearly, either as numbers, summaries, or JSON-based insights.
  • The workflow sends this response back to the user chat interface.

What happens if errors occur

  • If database connection fails, check the PostgreSQL credential details and network access.
  • If SQL query errors happen, the AI prompt may need updates to create valid SQL.
  • If the AI does not reply, verify the OpenAI API key and node configuration.
  • Use n8n logs to find where in the workflow problems occur.

Ideas for customization

  • Change the AI system message prompt to make replies more formal, short, or detailed.
  • Add more Postgres query nodes for special reports like sales trends or user behavior.
  • Connect the webhook with chat platforms like Slack for easier user access.
  • Store sensitive info like API keys in n8n secrets for better security.
  • Expand to other databases or schemas by adjusting SQL query code.

Summary of benefits

✓ The workflow lets users ask database questions by chat without SQL.

✓ Saves time by removing need to wait for engineers to write queries.

✓ Provides quick, accurate, easy-to-read answers from live data.

→ Helps non-technical people make fast data decisions.

Automate Supabase queries with n8n and OpenAI

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

This workflow is designed for PostgreSQL databases like Supabase. Using MySQL would require changing SQL queries and node configurations.
Yes, every time the AI processes a user question or generates SQL, it uses OpenAI API credits.
Check that PostgreSQL host, username, password are correct and that Supabase allows outside connections. Test credentials in n8n.
Yes, the workflow turns user chat messages into SQL queries automatically, so no SQL knowledge is needed.

Promoted by BULDRR AI

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.