A sophisticated natural language to SQL converter using FastAPI, LangChain, and Groq's Llama 3 API, featuring advanced query validation and security measures.
- Natural language to SQL conversion
- Session-based schema persistence
- Interactive schema management
- Query history tracking
- Copy-to-clipboard functionality
- Dark mode interface
-
Pattern-Based Security
- SQL injection prevention
- System command blocking
- Multiple statement detection
- Hex value detection
- Time-delay attack prevention
-
Natural Language Processing
- Informal text detection
- Non-SQL query filtering
- Query complexity analysis
- SQL keyword validation
-
Input Sanitization
- String literal validation
- Numeric overflow prevention
- Special character filtering
-
Create virtual environment and activate:
python -m venv venv .\venv\Scripts\activate # Windows source venv/bin/activate # Unix
-
Install dependencies:
pip install -r requirements.txt
-
Create
.envfile with your Groq API key:GROQ_API_KEY=your_api_key_here -
Run the application:
python app.py
- First visit: Enter your database schema
- Ask questions in natural language
- Get instant SQL translations
- View and copy previous queries from history
- Edit or clear schema as needed
✅ Valid Queries:
- "Show all users"
- "How many orders were placed today?"
- "Find total sales by category"
❌ Invalid Queries:
- "Hi, who are you?"
- "What's the weather today?"
- "SELECT * FROM users; DROP TABLE users;"
- Frontend: HTML/CSS/JS, Dark Mode Theme
- Backend: FastAPI, LangChain
- AI: Groq's Llama 3 API
- Security: NLTK, TensorFlow for query validation
- Database: PostgreSQL/MySQL support
Contributions are welcome! Please read our contributing guidelines before submitting pull requests.
MIT License