SQL Toolkit Block
What it does: Give AI agents the ability to query your databases, letting them look up information and answer questions using your actual data.
In simple terms: The SQL Toolkit is like giving your AI assistant a key to your database. When someone asks "How many orders did we get last week?" or "What's John's account balance?", the AI can actually look it up and give a real answer.
When to Use This
Use the SQL Toolkit when you need:
- ✅ AI to answer questions using live database data
- ✅ Natural language queries against your database
- ✅ Smart data lookups during conversations
- ✅ Dynamic reporting through AI assistants
- ✅ Self-service analytics for non-technical users
Example: Build a chat assistant for your sales team that can answer questions like "Show me our top 10 customers by revenue" by querying your database in real time.
Key Features
- Natural Language to SQL: AI translates questions into database queries
- Multiple Databases: Works with PostgreSQL, MySQL, and other SQL databases
- Safe Querying: Read-only options to protect your data
- Schema Awareness: AI understands your table structures
- Result Formatting: Clean, readable responses from raw data
How It Works
- User asks a question: "Which products are running low on inventory?"
- AI examines your database schema: Sees your tables and columns
- AI writes a query: Creates the appropriate SQL to find the answer
- Query runs: Executes against your database safely
- AI explains results: Formats the data into a helpful response
Setup Guide
Step 1: Connect Your Database
Provide your database connection details:
- Host address (where your database lives)
- Port number
- Database name
- Username and password
Step 2: Configure Access
| Setting | What It Does | Recommendation |
|---|---|---|
| Read Only | Prevent any data changes | Always enable for safety |
| Tables to Include | Which tables AI can access | Only include what's needed |
| Tables to Exclude | Tables to hide from AI | Exclude sensitive tables |
| Schema | Database schema to use | Default is usually "public" |
Step 3: Add to AI Agent
Include the SQL Toolkit as a tool for your AI agent. The agent will automatically use it when users ask data-related questions.
Common Use Cases
Business Intelligence Assistant
Let team members ask questions about sales, revenue, inventory, or any business data without needing to know SQL.
Customer Support Data Lookup
AI agents can look up customer order history, account status, or recent transactions during support conversations.
Executive Dashboards via Chat
Executives can ask "What were our sales yesterday?" and get an instant answer without waiting for reports.
Self-Service Analytics
Empower team members to get data insights on demand without bothering data analysts.
Inventory and Operations
Warehouse staff can ask about stock levels, shipping status, or order volumes.
What Gets Shared with AI
The AI agent receives:
- Table names: What tables exist in your database
- Column names and types: Structure of each table
- Sample data: Limited examples to understand content (if enabled)
- Query results: Data returned from queries
What You Get Back
After the AI queries your database:
- Query Results: The actual data from your database
- Formatted Response: AI's explanation of what it found
- Row Count: How many records matched
- Query Used: The SQL that was executed (for transparency)
Tips for Success
- Enable read-only mode - Never allow write access for safety
- Limit table access - Only expose tables the AI needs
- Use clear column names - "customer_email" is better than "ce1"
- Add descriptions - Help AI understand what tables contain
- Test common questions - Verify AI generates correct queries
Troubleshooting
| Problem | Likely Cause | Solution |
|---|---|---|
| Connection failed | Wrong credentials | Verify host, port, user, and password |
| No tables found | Wrong schema selected | Check database and schema name |
| Wrong results | AI misunderstood schema | Add table/column descriptions |
| Query errors | Complex question | Simplify the question or add examples |
| Slow responses | Large dataset | Add filters or limit result count |
Security Best Practices
- Use read-only database user - Create a user with SELECT only permissions
- Limit table exposure - Only include necessary tables
- Hide sensitive columns - Exclude columns with passwords, tokens, or PII
- Use connection pooling - Prevent too many open connections
- Monitor queries - Log what the AI is asking for
- Set timeouts - Prevent long-running queries from overloading your database