How ra-manuth/ai-agent-text_to_sql works
This repository is a command-line natural-language-to-SQL assistant with SQL Server and SQLite implementations. In the SQL Server workflow, the user’s question and detected schema go to Gemini; returned SQL is cleaned, checked, executed, and displayed, with schema refresh after qualifying DDL. The sampled create_db.py contains a separate SQLite assistant workflow and uses sales.db; despite the README describing sqlite_assistant.py, that file is absent from the provided tree. The graph reflects the sampled code and documented capabilities; no unsampled SQLite implementation is assumed.
Main entry points: sql_assistant.py SQL Server CLI · create_db.py Question handler · sales.db Sales database
Components 15
SQL Server assistant
- SQL Server CLI
sql_assistant.py - Schema detection
sql_assistant.py - SQL generation
sql_assistant.py - SQL cleaning
sql_assistant.py - Safety checks
sql_assistant.py - SQL execution
sql_assistant.py - SQL Server
SQLite assistant
- SQLite CLI
create_db.py - Question handler
create_db.py - SQL generation
create_db.py - SQL cleaning
create_db.py - SQL execution
create_db.py - Sales database
sales.db
External services
- Gemini API
Other components
- User
Connections 17
- User → SQL Server CLI: asks question
sql_assistant.py - SQL Server CLI → Schema detection: loads schema
sql_assistant.py - SQL Server CLI → SQL generation: sends question and schema
sql_assistant.py - SQL generation → Gemini API: requests SQL
sql_assistant.py - SQL Server CLI → SQL cleaning: cleans response
sql_assistant.py - SQL Server CLI → Safety checks: checks SQL
sql_assistant.py - SQL Server CLI → SQL execution: runs SQL
sql_assistant.py - SQL execution → SQL Server: queries and updates
sql_assistant.py - SQL Server CLI → User: prints results
sql_assistant.py - User → SQLite CLI: asks question
create_db.py - SQLite CLI → Question handler: handles question
create_db.py - Question handler → SQL generation: requests SQL
create_db.py - SQL generation → Gemini API: requests SQL
create_db.py - Question handler → SQL cleaning: cleans response
create_db.py - Question handler → SQL execution: runs SQL
create_db.py - SQL execution → Sales database: queries and updates
create_db.py - SQLite CLI → User: prints results
create_db.py