Skip to content

seanmaman/Text2SQL-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQL AI Agent - Functional Specification

Overview

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.

Core Functionality

1. Natural Language Processing

  • 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

2. SQL Generation & Execution Flow

User Input → AI Processing → SQL Generation → Security Validation → Database Execution → Results Display

3. Security Layer

  • 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

Key Components

Input/Output

  • Interactive CLI: Command-line interface for user queries
  • Natural Language Input: Plain English database questions
  • Formatted Results: Table-formatted query results with row counts

Processing Engine

  • AI Model: Uses Ollama LLM (configurable model)
  • Schema Awareness: AI knows database structure for accurate queries
  • Functional Design: Clean, stateless function-based architecture

Data Source

  • Database: SQLite database with revenue and player data
  • Tables:
    • revenue: Transaction and purchase data
    • master_data: Player statistics and levels

User Workflow

  1. Start Agent: Run python sql_agent.py
  2. View Schema: Database structure displayed on startup
  3. Ask Questions: Type natural language queries
  4. Get Results: View SQL query and formatted results
  5. Exit: Type 'exit' or 'quit' to end session

Configuration

All settings managed via settings.json:

  • AI model selection and parameters
  • Database location
  • Security rules
  • Logging preferences

Safety Features

  • Comprehensive logging of all operations
  • Query validation before execution
  • Error handling with user-friendly messages
  • Audit trail in log files

Use Cases

  • Business intelligence queries
  • Data exploration
  • Report generation
  • Database learning tool
  • Safe database access for non-technical users

About

A tool that converts natural language into queries that fits the related database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages