How it works
Question in Your question is checked for length and rate-limited.
AI writes SQL GPT-4o mini (via OpenRouter) turns it into one PostgreSQL SELECT.
Safety check The query is rejected if it isn't a single read of the sales table — no writes, no system tables, no multiple statements.
Read-only query It runs in a read-only transaction under a SELECT-only role, capped at 100 rows. If the SQL fails, the AI gets one chance to correct it.
Plain answer The AI summarises only the rows that came back. You see the SQL and the result table too.
About this demo
The original assistant is an n8n workflow that answers sales questions in Slack using an AI agent with a PostgreSQL tool. This page is a separate, public version of the same idea: it never touches the original workflow or its database.
The data is a public sample dataset (240 rows, one sale per day) — no customer or personal information.
n8n (original) OpenRouter · GPT-4o mini PostgreSQL Node.js
AI answers can still be wrong. The SQL is shown under each answer so you can check it.