SQL Query Writer
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.
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
Sign in to suggestTools 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.
Forge Auto-recommended matches
Tools
-
GitHub Copilot transform 30%
Why: caps 0/0 · domain code · io-match
-
Cursor transform 30%
Why: caps 0/0 · domain code · io-match
-
Replit AI transform 30%
Why: caps 0/0 · domain code · io-match
-
Tabnine transform 30%
Why: caps 0/0 · domain code · io-match
-
Cody (Sourcegraph) transform 30%
Why: caps 0/0 · domain code · io-match
-
Windsurf transform 30%
Why: caps 0/0 · domain code · io-match
-
Lovable transform 30%
Why: caps 0/0 · domain code · io-match
Report compatibility
Tell the community which tool you used this skill with, and whether it worked.
Suggest a pairing
Recommend a tool or workflow pack that this skill works well with. Up to 5 recommendations per day.