Text-to-SQL Agent Performance Documentation
Accuracy: 58.75%
A LangGraph-based agent converts natural language queries to SQL using Groq's Llama 3-70B and executes them against the Pagila database. The agent retries up to 3 times on errors, logs successful queries to output_queries.txt, and saves results to results.txt.
- Docker (for PostgreSQL container)
- Python 3.9+ with libraries:
pip install langgraph psycopg2 python-dotenv groq
- Groq API Key (set as environment variable
GROQ_API_KEY)
-
Clone Pagila Database
git clone https://github.com/devrimgunduz/pagila.git cd pagila -
Start PostgreSQL with Docker
docker-compose up -d # Launches Pagila database on port 5432 -
Initialize Database
docker exec -it pagila psql -U postgres -c "CREATE DATABASE pagila;" docker exec -i pagila psql -U postgres pagila < pagila-schema.sql docker exec -i pagila psql -U postgres pagila < pagila-data.sql
-
Configure Database Connection
Inmain.ipynb, update credentials:import psycopg2 conn = psycopg2.connect( host="localhost", port=5432, user="postgres", password="postgres", # Default Docker setup database="pagila" )
-
Run the Agent
Executemain.ipynbto start processing natural language queries.
(Previous test cases and score breakdown remain unchanged from original documentation)
-
Docker Connection Issues
- Verify container is running:
docker ps -a - Check logs:
docker logs pagila
- Verify container is running:
-
Empty Results
- Confirm table names/aliases match Pagila schema (e.g.,
cityvsaddress.city_id).
- Confirm table names/aliases match Pagila schema (e.g.,
-
Groq API Errors
- Ensure environment variable is set:
export GROQ_API_KEY="your-key-here"
- Ensure environment variable is set:
-
Schema Awareness
Current agent lacks explicit knowledge of Pagila's table relationships (e.g.,customer → address → city → country). -
Error-Driven Retries
Future versions could parse PostgreSQL errors to guide SQL correction (e.g., missing column → suggest joins). -
Performance Scaling
Test with larger datasets like Pagila's 16k+ rental records.
This enhanced documentation now provides full reproducibility while maintaining clarity about performance outcomes.
