A small demonstration of turning a natural language question into a SQL query using an LLM, based on the database schema in schema.txt.
It uses a simple two-layer pattern:
- Generation layer: produces a SQL query from the user’s request.
- Validation layer: review the generated query for safety & consistency.
Input:
List all matches where the home team scored more than 2 goals
Output:
SELECT * FROM matches WHERE home_score > 2Edit schema.txt to match your database tables/columns and relationships.
pip install -r requirements.txtSet API_KEY for your shell session:
$env:API_KEY="GEMINI_API_KEY"then run the app.
python main.py- Output depends on your schema and prompt.
- Generated respone will not include any unsafe deletion/modification query
- LLM-based validation can help, but it’s not a substitute for a real SQL parser, and it absolutely needs more database-side checks.