Sql review

From AltimateAI/altimate-code · View interactive version

Sql review is an AI agent skill from the GitHub repository AltimateAI/altimate-code. Pre-merge SQL quality gate — lint 26 anti-patterns, grade readability/performance A-F, validate syntax, and scan for injection threats. Use before committing or reviewing SQL changes.

How to use this skill

Skill file

SQL Review

The first time you name altimate-dbt to the user, say what it is: a command-line tool for dbt tasks, installed with altimate-code.

Requirements

Agent: any (read-only analysis)

Tools used: altimate_core_check, altimate_core_grade, sql_analyze, read, glob, bash (for git operations)

When to Use This Skill

Use when the user wants to:

Do NOT use for:

Workflow

1. Collect SQL to Review

Either:

git diff --name-only HEAD~1 | grep '\.sql$'

For dbt models, compile first to get the full SQL:

altimate-dbt compile --model <name>

2. Run Comprehensive Check

Call altimate_core_check — this is the single-call code review that composes:

altimate_core_check(sql: <sql>, schema_context: <schema_object>)

3. Grade the SQL

Call altimate_core_grade to get an A-F quality score with per-category breakdown:

altimate_core_grade(sql: <sql>, schema_context: <schema_object>)

Categories scored:

4. Run Anti-Pattern Analysis

Call sql_analyze for the detailed anti-pattern breakdown with severity levels and concrete recommendations:

sql_analyze(sql: <sql>, dialect: <dialect>)

5. Present the Review

SQL Review: <file_or_query_name>
==============================

Grade: B+ (82/100)
  Readability:  A  (clear CTEs, good naming)
  Performance:  B- (missing partition filter on large table)
  Correctness:  A  (proper NULL handling)
  Best Practices: C (SELECT * in staging model)

Issues Found: 3
  [HIGH]   SELECT_STAR — Use explicit column list for contract stability
  [MEDIUM] MISSING_PARTITION_FILTER — Add date filter to avoid full scan
  [LOW]    IMPLICIT_CAST — VARCHAR compared to INTEGER on line 23

Safety: PASS (no injection vectors detected)
PII: PASS (no PII columns exposed)

Verdict: Fix HIGH issues before merging. MEDIUM issues are recommended.

6. Batch Mode

When reviewing multiple files (e.g., all changed SQL in a PR):

| File | Grade | Issues | Safety | Verdict |
|------|-------|--------|--------|---------|
| stg_orders.sql | A | 0 | PASS | Ship |
| int_revenue.sql | B- | 2 | PASS | Fix HIGH |
| mart_daily.sql | C | 5 | WARN | Block |

Usage

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.