Script Review Agent
Risk-scores a SQL change script and returns a structured JSON verdict: severity, per-finding category, line numbers, remediation, and a suggested rollback. Designed to sit in front of the approval workflow, not as a chat toy.
Inputs
- Script (required), the SQL under review.
- Connection (optional), when present, the agent introspects the schema and grounds findings on real object names, letting it flag references to objects that don't exist.
- Notes (optional), free-form context (ticket ref, rollout plan).
Output shape
{
riskScore: 'low' | 'medium' | 'high' | 'critical',
findings: [
{ type, severity, message, line, suggestion, refs }
],
summary: 'one-paragraph review',
suggestedRollback: 'SQL to undo this script' | null
}
Detection surface
- Destructive ops: DROP / TRUNCATE / DELETE-without-WHERE / UPDATE-without-WHERE
- ALTER COLUMN that narrows a type or drops NOT NULL
- Lock/hot-path hazards: CREATE INDEX without CONCURRENTLY (Postgres), blocking ALTER TABLE
- Missing transaction wrapping where the engine supports it
- Over-broad grants (GRANT ALL, GRANT TO PUBLIC)
- Hardcoded credentials in SQL
- Cross-schema references that won't resolve in the target environment
- References to non-existent schema objects (connection-grounded only)
Scoring rubric
An irreversible destructive op with no accompanying rollback forces riskScore = critical. Otherwise the model scores against cumulative findings.
Wire it into approval
Set ai_script_review_mode = auto (Settings → AI) to auto-review every submitted script and attach the verdict before it enters the approval queue, a review gate rather than an on-demand action.