SQL AI Agent is a secure, natural language SQL query generator that converts plain English requests into SQL queries using AI (Ollama LLM). It provides a safe, read-only interface to database queries with built-in security validation.
- Input: User types queries in plain English (e.g., "Show me all VIP players")
- Processing: AI model (Ollama) converts the request to SQL
- Output: Valid SELECT statement ready for execution
User Input → AI Processing → SQL Generation → Security Validation → Database Execution → Results Display
- Read-Only Operations: Only SELECT statements allowed
- SQL Injection Protection: Blocks dangerous patterns and keywords
- Validation: Every query is validated before execution
- Forbidden Operations: No DELETE, DROP, UPDATE, INSERT, ALTER operations
- Interactive CLI: Command-line interface for user queries
- Natural Language Input: Plain English database questions
- Formatted Results: Table-formatted query results with row counts
- AI Model: Uses Ollama LLM (configurable model)
- Schema Awareness: AI knows database structure for accurate queries
- Functional Design: Clean, stateless function-based architecture
- Database: SQLite database with revenue and player data
- Tables:
- revenue: Transaction and purchase data
- master_data: Player statistics and levels
 
- Start Agent: Run python sql_agent.py
- View Schema: Database structure displayed on startup
- Ask Questions: Type natural language queries
- Get Results: View SQL query and formatted results
- Exit: Type 'exit' or 'quit' to end session
All settings managed via settings.json:
- AI model selection and parameters
- Database location
- Security rules
- Logging preferences
- Comprehensive logging of all operations
- Query validation before execution
- Error handling with user-friendly messages
- Audit trail in log files
- Business intelligence queries
- Data exploration
- Report generation
- Database learning tool
- Safe database access for non-technical users