What This Automation Does ✅
This workflow lets users talk with a database using simple chat messages. It turns what users say into SQL queries automatically. Then it runs those queries on a Supabase PostgreSQL database. Finally, it talks back with easy-to-understand answers.
The main problem solved is saving users time from writing hard SQL queries. Users get faster answers without needing SQL knowledge.
This tool helps both data experts and non-technical users get data quickly and clearly.
How This Workflow Works: Inputs → Process → Outputs
Inputs
- User chat messages from a chat interface or API.
- Database connection details to Supabase PostgreSQL.
- OpenAI API credentials to generate SQL and responses.
Processing Steps
- Listen for new chat messages using the LangChain Chat Trigger.
- Send user text to OpenAI chat model to understand and create SQL commands.
- Get database schema info using PostgresTool nodes. This helps AI know table and column details.
- Run the AI-created SQL query on Supabase with a PostgresTool node.
- Use AI to format the SQL query results into simple chat replies.
Output
Returns clear, conversational answers with the requested data from the database back to the user.
Who Should Use This Workflow
This works for people who want to get data from a PostgreSQL database quickly without writing SQL.
It helps data analysts and business team members who ask many questions daily.
Non-technical workers can also use it because they just type questions in normal language.
Tools and Services Used
- n8n: Automates workflows and connects all parts.
- Supabase PostgreSQL: Stores data queried by AI.
- OpenAI Chat Model: Creates SQL and chat answers.
- LangChain nodes (Chat Trigger, Agent): Manages chat input and AI guidance.
- PostgresTool nodes: Get schema info and run SQL queries.
Beginner Step-by-Step: How to Use This Workflow in n8n
Step 1: Import the Workflow
- Download the workflow file using the Download button on this page.
- Open n8n editor where you want to use the workflow.
- Click on the menu and choose “Import from File.”
- Select the downloaded file to add the workflow to n8n.
Step 2: Configure Credentials and Settings
- Add credentials for Supabase PostgreSQL with host, database name, username, and password.
- Enter your OpenAI API Key in the appropriate credential node.
- Check if table names or other database details need updating in the nodes.
Step 3: Test the Workflow
- Send a test chat message using the connected chat interface, like “Show sales from last month.”
- Confirm that the AI creates and runs SQL, then returns an answer.
Step 4: Activate the Workflow
- Turn on the workflow in n8n to accept real user messages.
- Use the provided webhook URL to connect a chat app or testing tool.
If hosting the workflow yourself, consider self-host n8n for better control.
Customization Ideas ✏️
- Change AI system messages to teach the bot specific company language.
- Adjust SQL queries in PostgresTool nodes for JSON data or different output formats.
- Add more database schemas to the schema query if needed.
- Insert a code node after querying to format or summarize data output.
Troubleshooting 🔧
- Can not connect to PostgreSQL database: Check host, username, and password. Also verify network access to Supabase.
- OpenAI API key errors: Make sure the API key is right and quota not used up.
- SQL syntax errors: Fix AI instructions in system prompt to get better queries.
- Chat messages not triggering workflow: Verify webhook URL and node connections.
Pre-Production Checklist ✅
- Test database credentials and connection.
- Send sample chat messages to check trigger.
- Review AI system prompt for clear instructions.
- Run trial queries to confirm data access.
- Backup database before wide use.
Deployment Guide
Switch the workflow on inside n8n. Use the webhook URL from the LangChain Chat Trigger node in your chat tool. Watch workflow logs for errors or delays. Enable detailed logs during first runs for easy debugging.
Summary
→ Users chat naturally and get database answers fast.
✓ Saves 3+ hours daily by auto-writing SQL.
✓ Reduces mistakes from manual query building.
✓ Opens data access to non-technical team members.
✓ Easy to import and run in n8n with minimal setup.
