How mahnoorahmed-dev/nl2sql-crewai works
This is a natural-language-to-SQL application with a Streamlit interface, CrewAI orchestration, and a custom SQL Server tool. Its main workflow accepts a question, retrieves schema context, asks GPT-4 for SQL, executes the query, formats the result, and returns it to the user. The tool’s source shows the schema, prompting, LLM, execution, and formatting stages; the README documents the agent workflow. The CSV’s role is not established by the sampled source, so it is omitted.
Main entry points: text_to_sql_tool.py SQL tool · app.py Streamlit UI · run_crew.py Crew runner
Components 12
User interface
- Streamlit UI
app.py
Crew orchestration
- Crew runner
run_crew.py - CrewAI runtime
SQL translation
- SQL tool
text_to_sql_tool.py - Schema retrieval
text_to_sql_tool.py - Prompt building
text_to_sql_tool.py - SQL generation
text_to_sql_tool.py - Query execution
text_to_sql_tool.py - Result formatting
text_to_sql_tool.py
External systems
- SQL Server
- OpenAI GPT-4
Other components
- User
Connections 17
- User → Streamlit UI: enters question
- Streamlit UI → Crew runner: calls query
- Crew runner → CrewAI runtime: starts crew
- CrewAI runtime → SQL tool: dispatches tool
- SQL tool → Schema retrieval: retrieves schema
- Schema retrieval → SQL Server: reads metadata
- SQL tool → Prompt building: builds prompt
- Prompt building → SQL generation: provides context
- SQL generation → OpenAI GPT-4: requests SQL
- OpenAI GPT-4 → SQL generation: returns SQL
- SQL tool → Query execution: executes SQL
- Query execution → SQL Server: runs query
- SQL tool → Result formatting: formats rows
- Result formatting → CrewAI runtime: returns results
- CrewAI runtime → Crew runner: returns answer
- Crew runner → Streamlit UI: returns result
- Streamlit UI → User: shows result