Skip to main content
AIDiveForge AIDiveForge
🗃️

SQL Query Writer

Code & Development · by AIDiveForge · Apr 17, 2026 · Intermediate · ✓ 1 verified compat

Turn natural-language questions into validated, safe SQL against a known schema — with dry-run support.

🧠 Why it works

LLMs hallucinate column names and join keys when they don't see the schema, and silently produce queries that run but return wrong results. Forcing schema injection + an EXPLAIN-first validation step catches the two dominant failure modes (wrong columns, missing joins) before the query touches the database. The EXPLAIN output is also cheap feedback the LLM can self-correct against, turning a one-shot prompt into a verifiable loop.

⚙️ How it works

1) Connect, pull information_schema.columns + foreign-key graph, cache per-session. 2) Pick the top-k tables by fuzzy token match against the user question; inject their DDL as skill context. 3) Generate SQL in the target dialect with a system prompt that requires CTEs over subqueries. 4) Run EXPLAIN (Postgres) or EXPLAIN QUERY PLAN (SQLite); parse row-estimate + missing-index warnings. 5) If a LIMIT is missing and the estimate exceeds 10k, auto-append LIMIT 1000. 6) Return {sql, plan_summary, est_rows} — the model can read the plan and refine.

Description

Packaged skill for text-to-SQL that enforces schema awareness. Fetches table definitions, injects them as few-shot context, and always EXPLAINs before executing. Includes a dialect adapter for Postgres, MySQL, and SQLite.

Install this skill

A Claude skill is a skill.md file with YAML frontmatter and a markdown body. Drop the file into your tool of choice — or pick a different format if you use Cursor, Windsurf, Copilot, or something else.

Download skill.md
mkdir -p ~/.claude/skills/sql-query-writer \
  && curl -L https://aidiveforge.com/skill/sql-query-writer.skill-md \
       -o ~/.claude/skills/sql-query-writer/skill.md

Save to ~/.claude/skills/sql-query-writer/skill.md

Recommended Use

Tools and workflow packs this skill pairs well with. Forge picks are auto-generated from category + capability signals; Community picks are added by people who've used the pairing.