Slack data Q&A bot for your SQL Server database

@-mention the bot in Slack with any plain-English question. It queries your SQL Server database, summarizes the answer, and shows the exact SQL it ran.

Agentic Task
SQL ServerSlack BotOperationsProductAI ReportsResearch & Monitoring

Build me a Slack data Q&A bot that turns plain-English questions into safe, read-only SQL Server queries and posts the answer back in Slack.

Trigger: an incoming Slack webhook (Slack Events API) for the app_mention event in a designated analytics channel, plus the message.channels event when the bot is replied to inside an existing thread it started. Verify Slack's signing secret, respond 200 immediately, and process the event asynchronously. The bot identity should be the Slack Bot (slackbot) integration so it can receive app_mention events and post as a bot.

Agent behavior on each mention:

1. Extract the user's question from the Slack event (strip the bot mention and any leading whitespace). Capture the channel, thread_ts (use the parent ts if this is a new mention, or the existing thread_ts if it is a reply), and the asking user id so the final reply can address them.

2. Ground in the schema before generating any SQL. Call SQL Server's List Tables operation to see what user tables exist, then call List Columns for the small subset of tables that look relevant to the question. Do not assume table or column names. If the question references entities you cannot map to a real table after this lookup, post a clarifying question in the same Slack thread (using Slack Bot's Send a Message with thread_ts set) and stop.

3. Generate a single T-SQL SELECT statement. Hard guardrails: SELECT only. Refuse anything containing INSERT, UPDATE, DELETE, MERGE, TRUNCATE, DROP, ALTER, CREATE, EXEC, EXECUTE, or sp_ prefixed procedures. Always include a row cap: TOP (100) for ungrouped queries, or ORDER BY ... OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY when pagination semantics are needed. Use square brackets around identifiers ([Orders], [Customer Name]). Never interpolate user values directly into the SQL string. Use @p1, @p2, @p3 placeholders and pass values through the params array per the SQL Server common_docs.

4. Run the query through SQL Server's Custom Query operation with the parameterized SQL and params array. If it errors (invalid object name, invalid column, syntax), feed the error back into the agent loop, regenerate the SQL using the schema you already fetched, and try once more. After two failures, post the error in-thread in plain English and stop.

5. Summarize the result and reply in the same Slack thread with Slack Bot's Send a Message (channel = original channel, thread_ts = the thread you are in). The reply must contain, in order: a one-line restatement of the question the bot understood; a short plain-English narrative answer (one to three sentences) grounded in the actual returned numbers; a compact Slack-formatted table of up to 10 rows from the result set (use mrkdwn-friendly fixed-width columns inside a triple-backtick code block, and note the total row count if more than 10 rows were returned, capped at the 100-row hard limit); and a final section labeled 'SQL' containing the exact T-SQL that ran inside a triple-backtick block so analysts can audit it.

6. Ambiguity handling. If the question is missing a time window, an entity scope, or a metric definition the schema does not pin down (for example, 'top customers' without defining 'top by what'), ask one focused clarifying question in-thread before running anything. Do not guess.

7. Safety and limits to enforce in code, not just in prompts: reject any generated SQL that does not start with SELECT or WITH (after trimming whitespace) and does not contain at least one of TOP / FETCH NEXT; cap returned rows shown in Slack at 10 even if the database returned more; cap the SQL Server response at 100 rows; do not echo the database connection details in Slack ever.

Integrations to use: SQL Server (sql-server) with operations List Tables, List Columns, and Custom Query; Slack Bot (slackbot) with operation Send a Message for replies. The bot must be invited to the analytics channel the user designates during setup.

Configurable inputs at setup time: the SQL Server credential, the Slack Bot credential, the list of channel IDs where the bot is allowed to answer, an optional allowlist of schemas or tables the agent is permitted to query (default: all user tables in dbo), and the row cap to display in the reply table (default 10, max 100).

Additional information

What does this prompt do?
  • Lets your team @-mention a bot in Slack with plain-English questions like "How many trials converted last month?" or "Who are our top 10 customers by revenue?"
  • Reads your SQL Server database structure on the fly, writes a safe read-only query, runs it, and replies right back in the Slack thread.
  • Posts a short written answer, a compact table of up to 10 rows, and the exact SQL it ran so analysts can audit, copy, or improve it.
  • Refuses anything that would change data, so non-technical teammates can self-serve answers without breaking the database.
What do I need to use this?
  • A Microsoft SQL Server database (Azure SQL, Amazon RDS, Google Cloud SQL, or self-hosted) with a read-only login.
  • A Slack workspace where you can install a bot and invite it to a channel.
  • The name of the analytics channel (or channels) where the bot should answer questions.
How can I customize it?
  • Choose which Slack channels the bot listens in, and whether it answers in threads only or also at the top level.
  • Limit which tables, schemas, or columns the bot can see, which is useful for hiding PII or sensitive columns.
  • Adjust the row cap on the reply table (default is 10) and tweak how the bot phrases its written answer.

Frequently asked questions

Can the bot accidentally change or delete data in our database?
No. It is hard-wired to only run read-only queries. Anything that would insert, update, delete, or alter data is rejected before it touches the database.
Does it understand our specific tables and column names?
Yes. Before answering each question, the bot inspects your database structure so it uses your real table and column names instead of guessing.
What happens if a question is too vague to answer?
The bot asks a clarifying question right in the Slack thread. You can answer in plain English and it will try again, instead of running a bad query.
Will this work on Azure SQL, AWS RDS, or a self-hosted server?
Yes. Anywhere General Input can reach your SQL Server. You will need to allow our connection IP in your database firewall, then plug in host, port, and a read-only login.
Can analysts double-check the bot's work?
Every Slack reply includes the exact SQL the bot ran, plus how many rows it returned. Analysts can copy the query, audit it, or paste it into their own tools.

Turn your SQL Server database into a Slack data assistant.

Connect Slack and SQL Server once, and your team can ask questions in plain English without learning SQL.