sql-diagram

A tool that draws a SQL query's execution steps or shows where its output columns come from. SQL is the language commonly used to read and combine data in databases.

In plain words
What is it for?
Use it to explain or review a query's plan, trace column lineage, inspect table joins, and test the query's behavior on small data.
Why use it?
A diagram makes joins, filters, ordering, and column origins easier to follow, while small sample data can expose problems the diagram cannot show.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/andre-salvati/databricks-template/sql-diagram
Any agent
npx skills add andre-salvati/databricks-template --skill sql-diagram
Clone the repo
git clone --depth 1 https://github.com/andre-salvati/databricks-template

Made for: Claude Code, Codex.

Per session 121 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,247 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00121 $0.03247
Opus 5 $0.00060 $0.01623
Sonnet 5 $0.00024 $0.00649
Haiku 4.5 $0.00012 $0.00325

Measured 3d ago against content hash 8766b60b237e, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

sql-diagram scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/skills/sql-diagram/SKILL.md · 182 lines

How it starts

The opening of the file, as written. The whole thing — 182 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Diagramming a SQL query

Diagram a SQL query and explain what it shows — either its execution steps or its column lineage.

Steps

  1. Get the SQL. If the user named a file, use it. If the query is embedded in Python (most of this repo's SQL lives in f-strings under scripts/), extract it to a scratch .sql file first and replace the interpolated placeholders with literalssqlglot parses SQL, not f-strings.
  2. Pick the mode. mode=plan (the default) answers "what does this query do, step by step"; mode=lineage answers "where does this output column come from". When the user asks about joins, stages, filters or ordering, they want plan.
  3. Run make sql-diagram sql=<path> name=<basename> comments=1 via Bash. It writes three files to reports/sql-diagram/: <basename>.sql (the query as analysed), .mmd and .svg. All of reports/ is gitignored generated output — never git add -f out of it. To keep a diagram as a committed example, copy the trio into .claude/skills/sql-diagram/examples/ and re-run against the copied .sql; because that file is the post-substitution query, the run reproduces the diagram exactly, which is why the .sql is kept beside the picture. Pass --stdout to scripts/sql_diagram.py for a throwaway look with no files written.
  4. Read the .mmd, show it in a ```mermaid fence, and explain it (see below). The .svg is the same graph for linking from prose where no Mermaid renderer is available.
  5. Simulate the query on small data (see Simulation) and deliver the diagram and the trace together as one HTML page in reports/sql-diagram/<basename>.html.

Explaining a query and reviewing one are different jobs. For an explanation the diagram is enough. For a review, read the .sql alongside it and treat the graph as an index into the text: it is authoritative on scans, joins and join predicates, and silent on filters, windows and projections (see the blind spots below). Defects severe enough to produce wrong numbers usually live in exactly the parts the picture omits.

Read the full file on GitHub · 182 lines

Files

What ships with it

4 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 182 lines · 121 tokens per session scan A 8766b60b237e

Subscribe to this mod's changes

sql-diagram is a skill published in the GitHub repository andre-salvati/databricks-template (83 stars, last pushed 27d ago), licensed Apache-2.0. It adds 121 tokens to every session and 3,247 once invoked, about $0.0006 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

data-parity

Validate that two tables or query results are identical — or diagnose exactly how they differ. Discover schema, identify keys, profile cheaply, then diff. Use for migration validation, ETL regression, and query refactor verification.

AltimateAI/altimate-code · 48 tokens

dbt-develop

REQUIRED before writing or modifying ANY dbt model. Invoke this skill FIRST whenever a task says "create", "build", "add", "modify", "update", "fix", or "refactor" a dbt model, staging file, mart, incremental, or snapshot. Skipping this skill is the leading cause of silent-correctness bugs — models that compile and…

AltimateAI/altimate-code · 294 tokens

dbt-troubleshoot

Debug dbt errors — compilation failures, runtime database errors, test failures, wrong data, and performance issues. Use when something is broken, producing wrong results, or failing to build. Powered by altimate-dbt.

AltimateAI/altimate-code · 50 tokens

dbt-schema-verify

REQUIRED after building or modifying ANY dbt model that has columns declared in schema.yml / models.yml. Run altimate-dbt schema-verify --model to diff actual columns against the spec, and treat any mismatch verdict as "not done." The most common reason "the build is green but the tests still fail" is that the model…

AltimateAI/altimate-code · 216 tokens

cost-report

Analyze Snowflake query costs and identify optimization opportunities.

AltimateAI/altimate-code · 12 tokens

dbt-test

Add schema tests, unit tests, and data quality checks to dbt models. Use when validating data integrity, adding test definitions to schema.yml, writing unit tests, or practicing test-driven development in dbt. Powered by altimate-dbt.

AltimateAI/altimate-code · 53 tokens