Natural language queries (Governed SQL)

Learn about how you can use natural language queries with the Exasol Governed SQL MCP Server.

The Exasol Governed SQL MCP Server translates plain English questions into read-only SQL queries for Exasol and executes them against your database. Instead of writing SQL by hand, you describe what you want in natural language and the server handles the rest.

Governed SQL enforces read-only query execution, so it will not modify your data.

How it works

Governed SQL uses a local LLM (running on your machine at Ollama or LM-Studio) to convert a natural language question into a SQL query. It uses a langgraph workflow to govern the SQL generation process. When you ask What were total sales by region last quarter?, the local LLM examines your database schema, understands the relationships between tables, and generates the appropriate Exasol-specific SQL.

Because the LLM runs locally, your database metadata and queries never leave your environment. This is a key difference from cloud-based text-to-SQL solutions.

How it relates to the MCP Server

Exasol provides two complementary MCP servers:

MCP Server:
Exposes database metadata and raw query execution to AI assistants. It lets an AI tool browse schemas, describe tables, search for objects, and run SQL you provide.
Governed SQL MCP Server:
Adds a natural language layer with a local LLM. It generates read-only SQL from your plain English questions and executes it.

You can use the different MCP servers independently or together. The base MCP Server is useful when you want direct control over queries. Governed SQL is useful when you want to ask questions without writing SQL while keeping data sovereign.

Prerequisites

  • An Exasol database instance with connection credentials

  • Python 3.12 or higher

  • A local LLM server: Ollama or LM-Studio

  • An MCP-compatible AI client (such as Claude Desktop)

Install

Install the package using uv:

Copy
uv tool install exasol-mcp-server-governed-sql@latest

Start the server

Start Governed SQL as an HTTP server:

Copy
exasol-mcp-server-governed-sql-http --host="0.0.0.0" --port=<port>

Example usage

Once the server is connected, you can ask questions in plain English through your AI assistant. For example:

  • What are the top 10 customers by revenue this year?
  • How many orders were placed last month, broken down by product category?
  • Show me all employees who joined in the last 90 days.
  • What is the average order value per region?

The server translates each question into Exasol SQL, executes it, and returns the results directly in the conversation.

Tips for accuracy

Text-to-SQL works best when the LLM has clear context about your database structure. Keep these points in mind:

Schema design affects accuracy.

Descriptive table and column names (like customer_orders instead of tbl_co) help the model generate correct queries. If your schema uses abbreviations or internal naming conventions, accuracy may decrease.

Complex queries may need refinement.

Simple lookups and aggregations tend to produce accurate SQL. Multi-join queries, subqueries, or questions that require domain-specific business logic may need follow-up clarification or manual adjustment.

Review generated SQL before acting on results.

For important business decisions, check the generated SQL to confirm it matches your intent. The AI assistant typically shows you the SQL it generated, so you can verify the logic.

Narrow the scope when possible.

Specifying the schema, table, or time range in your question helps the model produce more precise queries. Show revenue from the sales.orders table for Q1 2026 is more likely to succeed than Show me revenue.

Next steps