A conversational SQL database chatbot built with Streamlit, LangChain, Groq, and Qwen 3.6 27B.
The application allows users to interact with SQL databases using natural language instead of writing SQL queries manually. For example, users can simply ask:
βShow me all students with marks above 80.β
The LangChain SQL Agent interprets the question, determines the required database operation, generates and executes the appropriate SQL query, and returns the result in a human-readable format.
- π¬ Ask questions about SQL databases using natural language
- π€ Powered by Qwen 3.6 27B through Groq
- π¦ Built using the LangChain SQL Agent
- ποΈ SQLite database support
- π¬ MySQL database support
- π§ SQLDatabaseToolkit for database operations
- π Automatic SQL query generation and execution
- π₯οΈ Interactive Streamlit interface
- πΎ Chat history using Streamlit session state
- π§Ή Clear conversation history
- π Secure runtime Groq API key input through the sidebar
| Technology | Purpose |
|---|---|
| Python | Core programming language |
| Streamlit | Web interface |
| LangChain | Agent and LLM orchestration |
| Groq | LLM inference platform |
| Qwen 3.6 27B | Language model |
| SQLite 3 | Local database |
| MySQL | Optional database |
| SQLAlchemy | Database connection layer |
User
β
Streamlit Chat Interface
β
LangChain SQL Agent
β
Qwen 3.6 27B via Groq
β
SQLDatabaseToolkit
β
SQLDatabase
β
SQLite / MySQL
β
SQL Query Result
β
Natural Language Response
The user does not need to write SQL manually. The agent determines what information is required, inspects the database schema, selects the appropriate SQL tools, executes the query, and converts the result into a natural-language response.
The main interface allows users to select their database and provide their Groq API key before starting a conversation with the database.
The SQL Agent understands natural-language questions, inspects the SQLite database, generates the required SQL query, executes it, and returns the result.
Example:
Show me all the records from the table.
The application can also be configured to work with a local database, allowing users to interact with stored data through natural-language questions.
Chatbot-sql/
β
βββ app.py
βββ student.db
βββ requirements.txt
βββ README.md
β
βββ assets/
βββ main-page.png
βββ sqlite-response.png
βββ local-database.png
The student.db file contains the local SQLite database used by the application.
git clone https://github.com/amnsingh05/Chatbot-sql.git
cd Chatbot-sqlpython -m venv chatbot-sqlWindows:
chatbot-sql\Scripts\activatepip install -r requirements.txtIf requirements.txt is not available, install the required packages manually:
pip install streamlit langchain langchain-community langchain-classic langchain-groq sqlalchemyThis project uses Groq for LLM inference.
Enter your Groq API key through the Groq API Key field in the Streamlit sidebar.
The API key is provided at runtime and does not need to be hard-coded into the source code.
Never commit your actual API key to GitHub.
Avoid code such as:
ChatGroq(
groq_api_key="YOUR_ACTUAL_API_KEY"
)For production deployments, use environment variables or Streamlit Secrets to manage credentials securely.
The project currently uses:
qwen/qwen3.6-27b
The model is accessed through Groq and provides the language and tool-calling capabilities required by the SQL agent.
From the project directory, run:
streamlit run app.pyAlternatively:
python -m streamlit run app.pyStreamlit will start the application and provide a local URL, typically:
http://localhost:8501
Open the URL in your browser to access the chatbot.
The project includes support for a local SQLite database.
The default database file is:
student.db
The application locates the database relative to the project directory:
dbfilepath = (Path(__file__).parent / "student.db").absolute()Once connected, users can ask natural-language questions about the database.
Show all students.
Which student has the highest marks?
Show students who scored more than 80 marks.
How many students are in the database?
What is the average marks of all students?
The application also provides an option to connect to a MySQL database.
When MySQL is selected, the application requests:
- MySQL Host
- MySQL Username
- MySQL Password
- MySQL Database Name
The connection is established using SQLAlchemy, allowing the LangChain SQL components to interact with the MySQL database.
Provides LangChain with an interface for connecting to and interacting with the SQL database.
Provides database-related tools that the SQL agent can use to inspect tables, retrieve schema information, and execute SQL queries.
Creates the SQL agent responsible for understanding natural-language requests and interacting with the database through the available SQL tools.
Connects LangChain to the Groq API and the selected Qwen model.
Together, these components allow the application to transform:
Natural Language
β
SQL Agent
β
SQL Query
β
Database
β
Result
β
Natural Language Answer
Never upload your Groq API key to GitHub.
Do not hard-code sensitive credentials into your source code.
For example, avoid storing your actual API key directly inside:
ChatGroq(
groq_api_key="YOUR_API_KEY"
)For local development, runtime input or environment variables can be used.
For public deployments, use Streamlit Secrets or environment variables to protect sensitive credentials.
Possible future enhancements include:
- π€ Upload custom SQLite databases
- π₯ Support separate databases for different users
- π Deploy the application online
- π Improve API-key management with Streamlit Secrets
- π Support additional database formats
- π Add database schema visualization
- π§ Improve SQL-agent error handling
- π Provide better explanations of generated queries and results
- π Add stronger database access controls
- π Add data visualization for query results
A future online version could allow each user to upload and interact with their own SQLite database.
User
β
Online Streamlit Application
β
Upload SQLite Database
β
Temporary User Database
β
LangChain SQL Agent
β
Qwen 3.6 27B via Groq
β
SQL Query
β
SQL Results
β
Natural Language Response
This architecture would prevent users from sharing the developer's local student.db and allow each user to work with their own database.
Aman Singh
B.Tech CSE | Generative AI Developer
- πΌ LinkedIn: linkedin.com/in/amnsingh0
- π GitHub: github.com/amnsingh05
If you find this project useful, consider giving the repository a β on GitHub.
This project is intended for educational and personal use.
If you plan to distribute or modify the project publicly, consider adding an appropriate open-source license such as the MIT License.