🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🕵️ SicherheitslückenBurn Out, Or Fade Away(14.09.2026 um 14:25 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11: Microsoft entfernt WMIC-Tool gegen Ransomware - ad-hoc-news.de(14.09.2026 um 07:58 Uhr)
🕵️ SicherheitslückenMicrosoft schließt Rekordzahl an Sicherheitslücken - techbook(14.09.2026 um 09:00 Uhr)
🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🕵️ SicherheitslückenBurn Out, Or Fade Away(14.09.2026 um 14:25 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11: Microsoft entfernt WMIC-Tool gegen Ransomware - ad-hoc-news.de(14.09.2026 um 07:58 Uhr)
🕵️ SicherheitslückenMicrosoft schließt Rekordzahl an Sicherheitslücken - techbook(14.09.2026 um 09:00 Uhr)

🔧 Programmierung 🕛 vor 2 Monaten 4 Min Lesezeit
0

From Natural Language to SQL with AI: Building an Intelligent SQL Query Generator Using Hugging Face and Streamlit

↗ Quelle (dev.to)
🗣️ Stimme:

Introduction



Writing SQL queries is a fundamental skill for developers, data analysts, and database administrators. However, not everyone knows SQL syntax, and even experienced developers spend time writing repetitive queries.



Recent advances in Generative AI and Large Language Models (LLMs) make it possible to convert plain English into SQL automatically. Instead of writing:



SELECT name, salary

FROM employees

WHERE department = 'IT'

ORDER BY salary DESC;



A user can simply ask:



"Show me all IT employees ordered by salary from highest to lowest."



The AI translates the request into SQL.



In this article, we'll build a Text-to-SQL application using:



Python

Streamlit

Hugging Face Transformers

SQLite

SQLAlchemy



We'll also discuss real-world applications, limitations, and best practices.



Why Text-to-SQL Matters



Organizations generate massive amounts of structured data stored in relational databases.



Business users often need answers without knowing SQL.



Examples include:



Sales managers checking monthly revenue

HR departments analyzing employee records

Finance teams generating reports

Customer support searching order history



AI enables these users to retrieve information using natural language.



Project Architecture

User Question





Hugging Face Model





Generated SQL Query





SQLite Database





Results





Streamlit Dashboard



The workflow is simple:



User enters a question.

AI generates SQL.

SQL executes against SQLite.

Results appear instantly.

Technologies Used

Technology Purpose

Python Backend

Streamlit Web Interface

Hugging Face LLM for Text-to-SQL

SQLAlchemy Database connection

SQLite Sample database

Installing Dependencies

pip install streamlit

pip install transformers

pip install torch

pip install sqlalchemy

pip install pandas

Creating a Sample Database

from sqlalchemy import create_engine



engine = create_engine("sqlite:///company.db")



engine.execute("""

CREATE TABLE employees(

id INTEGER PRIMARY KEY,

name TEXT,

department TEXT,

salary INTEGER

)

""")



Insert sample data:



engine.execute("""

INSERT INTO employees(name, department, salary)

VALUES

('Alice','IT',7500),

('Bob','Sales',5200),

('Carol','IT',8900)

""")

Loading a Hugging Face Model



One popular Text-to-SQL model is based on T5.



from transformers import AutoTokenizer, AutoModelForSeq2SeqLM



model_name = "tscholak/1wnr382e"



tokenizer = AutoTokenizer.from_pretrained(model_name)

model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

Converting Natural Language into SQL

question = "Show employees working in IT"



inputs = tokenizer(question, return_tensors="pt")



outputs = model.generate(**inputs)



sql = tokenizer.decode(outputs[0], skip_special_tokens=True)



print(sql)



Possible output:



SELECT *

FROM employees

WHERE department='IT';

Executing the SQL

import pandas as pd



result = pd.read_sql(sql, engine)



print(result)



Output:



id name department salary

1 Alice IT 7500

3 Carol IT 8900

Building the Streamlit Interface

import streamlit as st



question = st.text_input("Ask your database")



if st.button("Generate SQL"):

sql = generate_sql(question)




CODE
st.code(sql, language="sql")

result = pd.read_sql(sql, engine)

st.dataframe(result)




Now users only need to type questions such as:



Show all employees

List employees in Sales

Average salary by department

Highest paid employee

Real-World Applications

Business Intelligence



Employees can generate reports without learning SQL.



Healthcare



Doctors can retrieve patient records using natural language.



Banking



Analysts can summarize transactions through conversational queries.



E-commerce



Managers can ask:



"Which products sold the most last month?"



instead of writing complex SQL.



Challenges



Although Text-to-SQL is impressive, it has limitations.



Database Schema Understanding



The AI performs much better when it understands the database schema.



SQL Validation



Generated SQL should always be validated before execution.



Never execute AI-generated SQL directly in production.



Security



Restrict permissions to read-only whenever possible.



Avoid allowing AI to execute:



DELETE

UPDATE

DROP

ALTER



without human approval.



Best Practices



✅ Provide the database schema as context.



✅ Validate SQL syntax.



✅ Limit user permissions.



✅ Log generated queries.



✅ Review queries before execution.



Public GitHub Example



A complete open-source implementation can be found in projects like:







Streamlit Documentation:

Vanna AI:

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
The Gemini desktop app is now available for Windows
1 Quelle
Burn Out, Or Fade Away
1 Quelle
Windows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten From Natural Language to SQL with AI: Building an Intelligent SQL Query Generator Using Hugging Face and Streamlit

Thematisch verwandte Begriffe: From, Natural, Language, with · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...