For enterprise teams who need their AI agent to query structured data directly from a SQL database with strict security controls.
8 min read
Updated February 2026
Critical business data often lives in SQL databases that only developers or analysts can query. When a customer asks “Is my subscription active?” or a manager asks “How many orders shipped this week?”, someone has to write a query, run it, and relay the answer. That loop can take hours.
The SQL Database Connector lets your AI agent query your database directly, translating natural language questions into SQL and returning results in real time. All queries are read-only with configurable table restrictions and row limits to keep your data safe.
| Action | Description |
|---|---|
| Query | Execute a read-only SQL query generated from the user's natural language question |
| List Tables | Show available tables (restricted to allowed tables list) |
| Describe Table | Show column names, types, and descriptions for a specific table |
Data security is paramount. The SQL Database Connector enforces multiple layers of protection:
INSERT, UPDATE, DELETE, DROP, ALTER, CREATE, or TRUNCATE statements before execution.SELECT-only privileges. Even though ChatSpark enforces read-only at the application layer, a read-only database user provides defense in depth.SELECT privileges on target tablesSELECT-only privileges on the tables you want to expose| Field | Description | Example |
|---|---|---|
| DB Type | Database engine: postgresql, mysql, mssql, or mariadb | postgresql |
| Connection String | Full connection URI including host, port, database, and credentials | postgresql://readonly:***@db.example.com:5432/mydb?sslmode=require |
| Allowed Tables | Comma-separated list of tables the agent can query | orders, customers, products |
| Max Rows | Maximum number of rows returned per query (default: 100) | 50 |
After setup, open your AI agent and try these realistic queries:
Use the Test Connection button in settings first to verify the database is reachable and credentials work before testing through the chat widget.
Verify ChatSpark's egress IPs are whitelisted in your database firewall. Also check that the database is listening on the specified port and accepts external connections.
Double-check the username, password, and database name in your connection string. Some databases require SSL; make sure sslmode=require is included if your server enforces encrypted connections.
The agent tried to query a table not in your Allowed Tables list. Add the table to the allowlist if it should be accessible, or rephrase the question to target an allowed table.
If the query returns more rows than your Max Rows setting, results are truncated. Increase the limit if needed, or ask more specific questions to narrow the result set.