Skip to content

nof1eld/text-to-SQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

text-to-SQL

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:

  1. Generation layer: produces a SQL query from the user’s request.
  2. Validation layer: review the generated query for safety & consistency.

Example

Input:

List all matches where the home team scored more than 2 goals

Output:

SELECT * FROM matches WHERE home_score > 2

Schema

Edit schema.txt to match your database tables/columns and relationships.

Setup

1) Install dependencies

pip install -r requirements.txt

2) Configure your API key

Set API_KEY for your shell session:

$env:API_KEY="GEMINI_API_KEY"

then run the app.

Run

python main.py

Notes

  • 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.

About

A demonstration of converting natural language to an SQL query using an LLM

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages