MySQL Query Chatbot Using n8n
Budget: $10 – $30 USD
Objective
Build a lightweight n8n workflow where a chatbot answers user questions by reliably querying a MySQL database. The system should auto-discover schema, map questions to relevant tables, generate safe SQL, run it, and return consistent, readable results.
Scope (High-Level)
Catalog: Connect to MySQL, enumerate tables/columns, sample a few values, and cache a JSON “schema catalog” in an n8n Data Store. Refresh daily or on demand.
Embeddings: Create embeddings with text-embedding-3 from table/column names + brief descriptions. Store vectors in a temporary vector store for fast retrieval.
Chat → SQL: On a chat webhook, retrieve relevant schema via embeddings, then use GPT-4.1-mini to draft SELECT-only, deterministic SQL. Validate against whitelisted tables, limit rows, and execute with the MySQL node.
Answering: Return a clean explanation + compact table preview + generated SQL. Provide CSV/JSON download optionally.
Consistency, Safety, Observability
System prompt with strict guardrails (no DDL/DML, no secrets).
Low-temperature, few-shot exemplars for stable SQL patterns.
Schema validation, basic syntax checks, retries with clear errors.
Read-only DB user; per-schema whitelist; optional PII masking.
Logs/metrics: question → tables used → SQL → latency → row count.
Deliverables
n8n workflow export (JSON), ready to import.
README: setup, env vars, adding tables, rotating keys.
Demo set: 10 sample questions with expected outputs.
Success Criteria
≥95% correctness on the demo set, zero write operations, deterministic SQL for repeated questions, and run-time under a few seconds for typical queries.
Build a lightweight n8n workflow where a chatbot answers user questions by reliably querying a MySQL database. The system should auto-discover schema, map questions to relevant tables, generate safe SQL, run it, and return consistent, readable results.
Scope (High-Level)
Catalog: Connect to MySQL, enumerate tables/columns, sample a few values, and cache a JSON “schema catalog” in an n8n Data Store. Refresh daily or on demand.
Embeddings: Create embeddings with text-embedding-3 from table/column names + brief descriptions. Store vectors in a temporary vector store for fast retrieval.
Chat → SQL: On a chat webhook, retrieve relevant schema via embeddings, then use GPT-4.1-mini to draft SELECT-only, deterministic SQL. Validate against whitelisted tables, limit rows, and execute with the MySQL node.
Answering: Return a clean explanation + compact table preview + generated SQL. Provide CSV/JSON download optionally.
Consistency, Safety, Observability
System prompt with strict guardrails (no DDL/DML, no secrets).
Low-temperature, few-shot exemplars for stable SQL patterns.
Schema validation, basic syntax checks, retries with clear errors.
Read-only DB user; per-schema whitelist; optional PII masking.
Logs/metrics: question → tables used → SQL → latency → row count.
Deliverables
n8n workflow export (JSON), ready to import.
README: setup, env vars, adding tables, rotating keys.
Demo set: 10 sample questions with expected outputs.
Success Criteria
≥95% correctness on the demo set, zero write operations, deterministic SQL for repeated questions, and run-time under a few seconds for typical queries.