SQL execution environment designed for LLM agents that validates query correctness and detects performance bottlenecks. It uses metamorphic testing to ensure SQL queries return accurate results and autonomously optimizes queries with performance suggestions and safety controls.
sql_exenv is an advanced SQL execution environment specifically designed for Large Language Model (LLM) agents, enabling efficient and reliable PostgreSQL query optimization while validating correctness through innovative metamorphic testing techniques.
LLM-generated SQL queries can sometimes contain hidden semantic errors that lead to incorrect result sets. This tool addresses these issues promptly, significantly improving the reliability of LLM outputs.
To utilize the provided capabilities, users can employ the command line interface as follows:
python cli.py # Launch chat mode
python cli.py --query "SELECT * FROM users WHERE email='user5000@example.com'"
python cli.py --query "..." --validate-only # Skip optimization
python cli.py --query "..." --no-validation # Skip validation
Additionally, an autonomous agent can be executed via:
python run_agent.py
For those looking to integrate the features programmatically, the Python API allows for seamless interaction with the optimization agent:
from src.agent import SQLOptimizationAgent
agent = SQLOptimizationAgent()
result = await agent.optimize_query(
sql="SELECT * FROM users WHERE email='user@example.com'",
db_connection="postgresql://postgres:postgres@localhost:5432/demo",
)
print(result['success'], result['final_query'])
The tool operates through several components:
This repository aims to streamline and validate the SQL query optimization process for LLMs, providing a comprehensive environment that fosters improved accuracy and performance.
No comments yet.
Sign in to be the first to comment.