This repository contains the SQL Query Assistant plugin for the Vera AI test engine.
The SQL Query Assistant is a feature designed to translate natural language questions into executable SQL queries (PostgreSQL dialect). This plugin allows developers to test the performance, safety, and accuracy of the assistant using Vera's automated tests framework.
The main purpose of this plugin is to provide a structured way to:
- Simulate Feature Execution: Generate SQL queries based on natural language input and provided schema context.
- Verify via Static Checks: Perform programmatic checks on the generated SQL (e.g., ensuring no
destructive commands like
DROPorDELETEare present). - Evaluate via LLM-as-a-Judge: Use high-reasoning models to score the generated SQL against business logic, efficiency, and syntax correctness.
The plugin is structured as follows:
src/sql_query_assistant/plugin_impl.py: The entry point for Vera. It implements the required hooks to load test cases, run the feature, and trigger tests and evaluation.src/sql_query_assistant/core/data_models.py: Defines the Pydantic models for inputs (SqlQueryInput), outputs (SqlQueryOutput), and the final report row (SqlQueryRow).src/sql_query_assistant/core/static_checks.py: Contains the Python logic for programmatic tests of the SQL output.src/sql_query_assistant/core/generate_sql.py: A mock/wrapper for the actual SQL generation logic.src/sql_query_assistant/feature_tests/: Contains the datasets and specifications used during tests.
Developers contributing to the code of this plugin should focus on the following areas:
If the way the SQL is generated needs to change (e.g., switching to a different internal model or
adding pre-processing steps), update the run_feature hook in plugin_impl.py or the logic in
core/generate_sql.py.
To add a new metric (e.g., "SQL Dialect Compliance"):
- Update
LlmChecksColumnorStaticChecksColumnincore/data_models.py. - Update
SqlQueryRowto include the new field and its CSV alias. - Modify
SqlQueryRow.calculate_final_score()to incorporate the new metric into the weighted average. - Update the corresponding test hook in
plugin_impl.py.
Modify core/static_checks.py to add more robust programmatic verification, such as checking for
table existence against a schema or validating syntax using a SQL parser.
To install this plugin in editable mode for development:
uv pip install -e .