How hsmshubham007-code/text_to_sql works
This is a Streamlit natural-language interface for querying the Chinook music-store SQLite database through Groq. The principal flow is question submission, unsupported-topic refusal or SQL generation, schema context retrieval, SQL validation and bounded repair, read-only execution, and result display. The four documented database tools expose table listing, table inspection, schema overview, and SQL execution. The graph shows the tool registry and its database/safety layers separately; evaluation scripts and tests are excluded. Relationships are based on the README and sampled source; unsampled behavior is not inferred.
Main entry points: database_tools.py Database access · sql_generator.py SQL generation · agent_tools.py Tool registry · agent.py Agent response
Components 14
User interface
- Question UI
app.py
Agent and generation
- Agent response
src/agent.py - SQL generation
src/sql_generator.py - Generation prompt
prompts/sql_generation.txt
Database tools
- Tool registry
src/agent_tools.py - Table listing
src/agent_tools.py - Table inspection
src/agent_tools.py - Schema overview
src/agent_tools.py - SQL execution tool
src/agent_tools.py
Read-only storage
- Database access
src/database_tools.py - SQL safety
src/sql_safety.py - Chinook SQLite
data/chinook.db
Other components
- Business user
- Groq model
Connections 19
- Business user → Question UI: asks question
README.md - Question UI → Agent response: submits question
app.py - Agent response → SQL generation: delegates query
src/agent.py - SQL generation → Groq model: requests SQL
src/sql_generator.py - SQL generation → Generation prompt: loads prompt
src/sql_generator.py - SQL generation → Schema overview: retrieves schema
src/sql_generator.py - SQL generation → SQL execution tool: executes query
src/sql_generator.py - Tool registry → Table listing: registers tool
src/agent_tools.py - Tool registry → Table inspection: registers tool
src/agent_tools.py - Tool registry → Schema overview: registers tool
src/agent_tools.py - Tool registry → SQL execution tool: registers tool
src/agent_tools.py - Table listing → Database access: lists tables
src/agent_tools.py - Table inspection → Database access: reads schema
src/agent_tools.py - Schema overview → Database access: collects schemas
src/agent_tools.py - SQL execution tool → Database access: runs SQL
src/agent_tools.py - Database access → SQL safety: delegates execution
src/database_tools.py - Database access → Chinook SQLite: reads metadata
src/database_tools.py - SQL safety → Chinook SQLite: executes read-only
src/sql_safety.py - Agent response → Question UI: returns results
app.py