A Streamlit application that leverages LangChain and various LLM providers (OpenAI, Groq, Google, Anthropic) to create a safe, production-grade SQL querying assistant. Easily connect to your SQL Server database, configure an LLM, and get natural language insights with query execution and analysis.
- Features
- Prerequisites
- Installation
- Configuration
- Running the App
- Usage Guide
- Project Structure
- Dependencies
- Contributing
- License
- One-click connection testing to SQL Server via ODBC
- Support for multiple LLM providers: OpenAI, Groq, Google, Anthropic
- Safe SQL agent with enforced read-only rules
- Interactive, step-by-step query execution breakdown
- Live metadata and schema browsing
- Query history tracking and replay
- Python 3.8 or higher
- A SQL Server instance accessible over network
- API key for your chosen LLM provider (OpenAI, Groq, Google, or Anthropic)
-
Clone the repository
git clone https://github.com/ashifhusainoo7/SQLToNLP.git cd SQLToNLP -
Create and activate a virtual environment (recommended)
python -m venv venv source venv/bin/activate # macOS/Linux venv\Scripts\activate # Windows
-
Install dependencies
pip install -r requirements.txt
All configuration is done through the Streamlit sidebar.
- Server: Your SQL Server address (e.g.,
myserver\SQLEXPRESS) - Database: Target database name
- Username & Password: Credentials with read-only permissions
- Driver: Choose ODBC Driver 17 or 18 for SQL Server (or FreeTDS)
Click Test Database Connection to verify and initialize.
- LLM Provider: Select from OpenAI, Groq, Google, Anthropic
- Model: Choose model compatible with provider (e.g.,
gpt-4-turbo) - API Key: Enter your provider API key
- Temperature & Max Tokens (optional)
Click Initialize LLM to connect.
Start the Streamlit server:
streamlit run streamlit_with_sql.pyThis will open the UI in your default browser at http://localhost:8501.
Once the app is running, follow these steps:
- Enter SQL Server details in the sidebar
- Click 🔗 Test Database Connection
- Upon success, the Database status indicator turns ✅
- Select LLM provider and model
- Enter your API key and adjust parameters
- Click 🚀 Initialize LLM
- LLM status indicator turns ✅
- After database and LLM are ready, click ⚡ Create SQL Agent
- Agent status indicator turns ✅
- In the Query Interface, type natural language questions (e.g., "List users who haven't logged in today with their company names")
- Click 🔍 Execute Query to send to the agent
- View results and the generated SQL in the "View Execution Steps" expander
- Refresh Table Info to load current schema: total tables, sample schemas
- Expand Available Tables to browse object names
- Query history appears in the sidebar with timestamps and statuses
SQLToNLP/
├── streamlit_with_sql.py # Main application file
├── requirements.txt # Python dependencies
└── README.md # This documentation
See requirements.txt for the full list:
streamlit
pandas
sqlalchemy
langchain
langchain-openai
langchain-anthropic
langchain-google-genai
langchain-groq
langgraph
langchain_community
pyodbc
- Fork the repository
- Create a feature branch (
git checkout -b feature/YourFeature) - Commit your changes (
git commit -m 'Add feature') - Push to branch (
git push origin feature/YourFeature) - Open a Pull Request
This project is licensed under the MIT License. See LICENSE for details.