Added generic and database specific skills and debugged validator tool - #20
Conversation
…to display more benchmark info
There was a problem hiding this comment.
Pull request overview
This PR expands Sequel2SQL with database-specific semantic-model skills, an error-taxonomy knowledge base, and a confirmed-fixes (ChromaDB) retrieval layer, while also refactoring validator/result modeling and updating the benchmark harness to use the revised agent pipeline.
Changes:
- Added per-database semantic-model skill packs (SKILL.md + reference resources) and wiring for skills loading.
- Introduced error taxonomy markdown “skills” plus a retrieval helper (
get_error_taxonomy_skill). - Added confirmed-fix persistence/retrieval via ChromaDB, updated prompts/benchmark pipeline, and refactored validator result models.
Reviewed changes
Copilot reviewed 94 out of 107 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Adds pydantic-ai-skills lock entry |
| pyproject.toml | Adds pydantic-ai-skills dependency + dev group |
| .gitignore | Ignores confirmed-fixes chroma dir |
| tests/test_validator_fixes.py | Adds validator regression tests |
| tests/test_skills_loading.py | Adds skills toolset tests |
| tests/test_confirmed_fix_retrieval.py | Adds confirmed-fix retrieval test script |
| tests/inspect_chroma_db.py | Updates chroma inspection script |
| src/skills/toxicology-semantic-model/SKILL.md | Adds toxicology semantic skill |
| src/skills/toxicology-semantic-model/references/gotchas.md | Toxicology gotchas |
| src/skills/toxicology-semantic-model/references/metrics.md | Toxicology metrics |
| src/skills/toxicology-semantic-model/references/query_patterns.md | Toxicology query patterns |
| src/skills/superhero-semantic-model/SKILL.md | Adds superhero semantic skill |
| src/skills/superhero-semantic-model/references/gotchas.md | Superhero gotchas |
| src/skills/superhero-semantic-model/references/metrics.md | Superhero metrics |
| src/skills/superhero-semantic-model/references/query_patterns.md | Superhero query patterns |
| src/skills/student-club-semantic-model/SKILL.md | Adds student_club semantic skill |
| src/skills/student-club-semantic-model/references/gotchas.md | Student club gotchas |
| src/skills/student-club-semantic-model/references/metrics.md | Student club metrics |
| src/skills/student-club-semantic-model/references/query_patterns.md | Student club query patterns |
| src/skills/formula-1-semantic-model/SKILL.md | Adds formula_1 semantic skill |
| src/skills/formula-1-semantic-model/references/gotchas.md | Formula 1 gotchas |
| src/skills/formula-1-semantic-model/references/metrics.md | Formula 1 metrics |
| src/skills/formula-1-semantic-model/references/query_patterns.md | Formula 1 query patterns |
| src/skills/financial-semantic-model/SKILL.md | Adds financial semantic skill |
| src/skills/financial-semantic-model/references/gotchas.md | Financial gotchas |
| src/skills/financial-semantic-model/references/metrics.md | Financial metrics |
| src/skills/financial-semantic-model/references/query_patterns.md | Financial query patterns |
| src/skills/european-football-2-semantic-model/SKILL.md | Adds european_football_2 semantic skill |
| src/skills/european-football-2-semantic-model/references/gotchas.md | European football gotchas |
| src/skills/european-football-2-semantic-model/references/metrics.md | European football metrics |
| src/skills/european-football-2-semantic-model/references/query_patterns.md | European football query patterns |
| src/skills/debit-card-specializing-semantic-model/SKILL.md | Adds debit_card_specializing semantic skill |
| src/skills/debit-card-specializing-semantic-model/references/gotchas.md | Debit card gotchas |
| src/skills/debit-card-specializing-semantic-model/references/metrics.md | Debit card metrics |
| src/skills/debit-card-specializing-semantic-model/references/query_patterns.md | Debit card query patterns |
| src/skills/codebase-community-semantic-model/SKILL.md | Adds codebase_community semantic skill |
| src/skills/codebase-community-semantic-model/references/gotchas.md | Codebase community gotchas |
| src/skills/codebase-community-semantic-model/references/metrics.md | Codebase community metrics |
| src/skills/codebase-community-semantic-model/references/query_patterns.md | Codebase community query patterns |
| src/skills/card-games-semantic-model/SKILL.md | Adds card_games semantic skill |
| src/skills/card-games-semantic-model/references/gotchas.md | Card games gotchas |
| src/skills/card-games-semantic-model/references/metrics.md | Card games metrics |
| src/skills/card-games-semantic-model/references/query_patterns.md | Card games query patterns |
| src/skills/california-schools-semantic-model/SKILL.md | Adds california_schools semantic skill |
| src/skills/california-schools-semantic-model/references/gotchas.md | California schools gotchas |
| src/skills/california-schools-semantic-model/references/metrics.md | California schools metrics |
| src/skills/california-schools-semantic-model/references/query_patterns.md | California schools query patterns |
| src/query_intent_vectordb/search_similar_query.py | Adjusts distance→similarity conversion |
| src/query_intent_vectordb/embed_query_intent.py | Sets Chroma cosine space metadata |
| src/error_taxonomy/init.py | Adds taxonomy package init |
| src/error_taxonomy/generic_skills.py | Adds taxonomy skill loader |
| src/error_taxonomy/aggregation.md | Adds aggregation taxonomy guidance |
| src/error_taxonomy/filter_conditions.md | Adds filter taxonomy guidance |
| src/error_taxonomy/join_related.md | Adds join taxonomy guidance |
| src/error_taxonomy/logical.md | Adds logical taxonomy guidance |
| src/error_taxonomy/semantic.md | Adds schema-link taxonomy guidance |
| src/error_taxonomy/set_operations.md | Adds set-ops taxonomy guidance |
| src/error_taxonomy/structural.md | Adds select/structural taxonomy guidance |
| src/error_taxonomy/subquery_formulation.md | Adds subquery taxonomy guidance |
| src/error_taxonomy/syntax.md | Adds syntax taxonomy guidance |
| src/error_taxonomy/value_representation.md | Adds literal/value taxonomy guidance |
| src/db_confirmed_fixes/init.py | Adds confirmed-fixes package init |
| src/db_confirmed_fixes/README.md | Documents confirmed-fixes store |
| src/db_confirmed_fixes/db_confirmed_fixes.json | Adds seeded confirmed-fix corpus |
| src/db_confirmed_fixes/info.py | Adds seeding script |
| src/db_confirmed_fixes/retriever.py | Adds save/find/prune logic |
| src/database/database.py | Changes SQL execution guard behavior |
| src/ast_parsers/result.py | Introduces unified Pydantic result models |
| src/ast_parsers/init.py | Updates ast_parsers public API exports |
| src/agent/skills_config.py | Adds skills toolset + DB-skill instructions helper |
| src/agent/prompts/base_prompt.py | Updates tool/policy guidance text |
| src/agent/prompts/webui_prompt.py | Adds confirmed-fix workflow instructions |
| src/agent/prompts/benchmark_prompt.py | Rewrites benchmark prompt as standalone |
| benchmark/src/ui.py | Adds single-query mode + counts update |
| benchmark/src/sequel2sql_client.py | Runs full pipeline; adds usage limits & preprocess/cleanup execution |
| benchmark/src/prompt_generator.py | Adds single-record prompt extraction |
| benchmark/src/inference_engine.py | Adds inter-task sleep |
| benchmark/src/config.py | Updates provider configs (Gemini/Codestral) |
| benchmark/src/checkpoint_manager.py | Persists run metadata in checkpoint |
| benchmark/src/api_client.py | Updates provider description text |
| benchmark/main.py | Adds interactive single-query mode + run_config persistence |
| benchmark/README.md | Updates benchmark README model references |
| benchmark.sh | Updates model list output |
| src/chroma_db/f60bef43-d232-42a0-b54c-c354655c0ae1/length.bin | Adds Chroma persistence artifact |
| src/chroma_db/f60bef43-d232-42a0-b54c-c354655c0ae1/header.bin | Adds Chroma persistence artifact |
| src/chroma_db/f60bef43-d232-42a0-b54c-c354655c0ae1/link_lists.bin | Adds Chroma persistence artifact |
| src/chroma_db/be58dce8-6c8c-4bad-8bca-670bb1820eb2/length.bin | Adds Chroma persistence artifact |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| candidates = [] | ||
| ids_to_increment = [] | ||
| metadatas_to_update = [] | ||
|
|
||
| for doc, meta, dist, doc_id in zip(docs, metas, dists, ids): | ||
| similarity = 1.0 - dist | ||
| candidates.append( | ||
| { | ||
| "intent": doc, | ||
| "error_sql": meta.get("error_sql", ""), | ||
| "corrected_sql": meta.get("corrected_sql", ""), | ||
| "explanation": meta.get("explanation", ""), | ||
| "similarity": round(similarity, 4), | ||
| } | ||
| ) | ||
| # Best-effort increment usage_count | ||
| if ids_to_increment: | ||
| try: | ||
| collection.update( | ||
| ids=ids_to_increment, | ||
| metadatas=metadatas_to_update | ||
| ) | ||
| except Exception: | ||
| pass |
There was a problem hiding this comment.
find_similar_confirmed_fixes declares ids_to_increment / metadatas_to_update and has a "Best-effort increment usage_count" block, but those lists are never populated. As a result, usage_count is never updated even though the function appears to support it. Either implement the increment logic (e.g., read current usage_count from meta, increment, and queue updates) or remove the dead code to avoid misleading behavior.
| Each database gets its own ChromaDB collection under `chroma/<database_name>/`. Fixes are embedded by their **intent** (natural language description) using ChromaDB's default sentence-transformer model. | ||
|
|
||
| ### Core Functions (`store.py`) | ||
|
|
||
| | Function | Description | | ||
| |---|---| | ||
| | `save_confirmed_fix()` | Stores a confirmed fix with deduplication (intent similarity ≥ 0.8) | | ||
| | `find_similar_confirmed_fixes()` | Retrieves up to N fixes with cosine similarity ≥ 0.75 | | ||
| | `prune_confirmed_fixes()` | Tiered cleanup when collection exceeds 500 items | | ||
|
|
There was a problem hiding this comment.
This README describes store.py under a db_skills/ directory, but the implementation in this PR lives under src/db_confirmed_fixes/ (not db_skills) and the main module is retriever.py (plus info.py). Please update the module names and directory structure in the documentation so it matches the actual code layout.
| def test_db_skill_hint_present(): | ||
| """get_db_skill_hint returns a load_skill hint when a skill exists for the DB.""" | ||
| from src.agent.skills_config import get_db_skill_hint | ||
| hint = get_db_skill_hint("california_schools_template") | ||
| assert hint != "" | ||
| assert "load_skill" in hint | ||
| assert "california-schools-template-semantic-model" in hint | ||
|
|
||
|
|
||
| def test_db_skill_hint_absent(): | ||
| """get_db_skill_hint returns empty string when no skill exists for the DB.""" | ||
| from src.agent.skills_config import get_db_skill_hint | ||
| hint = get_db_skill_hint("nonexistent_db") | ||
| assert hint == "" |
There was a problem hiding this comment.
This test imports get_db_skill_hint from src.agent.skills_config, but skills_config.py defines get_db_skill_instructions (no get_db_skill_hint symbol). As written, the test will fail at import time. Either export a get_db_skill_hint alias (and keep its previous semantics), or update the tests (and any call sites) to use the new function name consistently.
| def test_skill_discovery(): | ||
| """SkillsToolset discovers all expected skills in the skills directory.""" | ||
| toolset = SkillsToolset(directories=[str(SKILLS_DIR)]) | ||
| skill_names = list(toolset.skills.keys()) | ||
| assert "db-query" in skill_names, f"db-query skill not found. Found: {skill_names}" | ||
| assert "california-schools-template-semantic-model" in skill_names, ( | ||
| f"california-schools-template-semantic-model not found. Found: {skill_names}" | ||
| ) |
There was a problem hiding this comment.
test_skill_discovery asserts that a skill named california-schools-template-semantic-model exists, but the skills directory in this PR contains california-schools-semantic-model (and no *-template-* variant). This will make the discovery test fail (and also suggests the DB→skill naming convention is inconsistent). Align the skill name: in SKILL.md (or the test expectations) so the generated DB skill name matches what SkillsToolset actually discovers.
|
@copilot can you make the changes for all the md files that you suggested? (the example names under skills) |
|
@aravindh28 I've opened a new pull request, #22, to work on those changes. Once the pull request is ready, I'll request review from you. |
Co-authored-by: aravindh28 <54079536+aravindh28@users.noreply.github.com>
Align SKILL.md `read_skill_resource` examples with actual skill IDs
…ncrement - save_confirmed_fix: initialize results = None before the conditional query block so the dedup check behaves deterministically instead of relying on the broad except to mask NameError - find_similar_confirmed_fixes: populate ids_to_increment and metadatas_to_update so usage_count is actually incremented on each retrieval (was previously dead code)
- Rename references from db_skills/store.py to db_confirmed_fixes/retriever.py - Add info.py and db_confirmed_fixes.json to documentation - Update directory tree to reflect current structure
- Point CHROMA_BASE at src/db_confirmed_fixes/chroma/ instead of the old src/db_skills/chroma/ path - Support inspecting all DBs (no args) or a specific one (CLI arg)
- Replace weak DDL-only blocklist with allowlist (SELECT/WITH/EXPLAIN) - Block DML (INSERT/UPDATE/DELETE) and all DDL/utility commands - Use word-boundary regex to avoid false positives on column names - Strip string literals before scanning to handle WHERE x = 'DELETE' - Strip SQL comments before checking first token
|
Working on this branch atm, will test all changes with new benchmarking scores and then merge to main |
Description
This PR is a cumulative integration of work across several feature branches (
generic-skills→clean-benchmark→validator-final-fix→testing-confirmed-fix). It introduces a complete tooling overhaul for the Sequel2SQL agent — adding validated SQL fix retrieval, a reworked AST validator, per-database semantic model skills, an error taxonomy knowledge base, and a restructured benchmark pipeline.🔧 Validator Overhaul (
src/ast_parsers/)EXPLAINon the live database instead of fragile AST-only parsing.tags.py) replacing the olderror_codes.py/errors.py/error_context.pymodules (all deleted).result.pymodel withValidationResultandValidationErrorOut— cleaner Pydantic output._explainno longer surface as SQL errors; schema cache invalidation afterpreprocess_sqlensures dynamically created tables are recognized.tests/run_validator_benchmark.py,tests/run_validate_with_db_benchmark.py) with full results intests/output/.🧠 Semantic Model Skills (
src/skills/)SKILL.mdentrypoint plus domain-specific references:gotchas.md,metrics.md, andquery_patterns.md.pydantic-ai-skillsusingload_skill('<db>-semantic-model').skills_config.pyfilters instructions to only the relevant DB skill, saving ~350–400 tokens per run.📚 Error Taxonomy (
src/error_taxonomy/)aggregation,syntax,join_related,semantic,logical,structural,filter_conditions,set_operations,subquery_formulation,value_representation.generic_skills.pyprovidesget_error_taxonomy_skill(category)— looks up best-practice fix strategies by category.🗃️ Confirmed Fixes Knowledge Base (
src/db_confirmed_fixes/)db_confirmed_fixes.json— 50 curated (intent → error SQL → corrected SQL → explanation) entries mapped to their benchmarkdb_id.info.py— one-time seeder script that embeds intents into per-database ChromaDB instances underchroma/<db_id>/.retriever.py—find_similar_confirmed_fixes()returns top-4 semantically similar fixes (no similarity threshold — raw ranking).save_confirmed_fix()with deduplication and pruning.tests/test_confirmed_fix_retrieval.py): 86% top-1 accuracy, 100% top-4 recall across all 50 entries.🤖 Agent & Prompt Updates (
src/agent/)execute_sql_query,validate_query,get_error_taxonomy_skill,find_similar_confirmed_fixes_tool.analyze_and_fix_sql,describe_database_schema,save_confirmed_fix_tool).analyze_and_fix_sqlfully restored — performs validation, schema-aware table filtering, similar example retrieval, taxonomy lookups, and confirmed fix retrieval.validate_queryand confirmed fixes as advisory guidance (not literal truth).📊 Benchmark Pipeline (
benchmark/)sequel2sql_client.py— a dedicated client for running the Sequel2SQL agent pipeline through the benchmark harness.config.py,api_client.py,ui.py, andmain.pyfor the new pipeline integration.BenchmarkOutput) for structured agent responses.Related Issue
This PR closes #
Motivation and Context
The Sequel2SQL agent previously lacked structured knowledge about common SQL error patterns and had no way to leverage previously confirmed fixes. The validator was brittle (AST-only, no live database checking), and there was no per-database semantic model to guide query repair.
This PR establishes a complete knowledge-augmented pipeline:
Together, these give the agent significantly richer context for producing correct SQL fixes in both benchmark and production (webui) modes.
Screenshots (if any)
Types of changes
Checklist: