---
name: "sql-query-writer"
description: "Draft one read-only SQL query grounded in a supplied schema and dialect. Use when the user needs: Get SQL, bound parameters, assumptions and a safe validation plan."
license: "Apache-2.0"
metadata: {"version": "2026-10-17.1", "category": "code-development", "publisher": "AIDiveForge"}
---

# SQL Query Writer

Get SQL, bound parameters, assumptions and a safe validation plan.

## Requirements

Provide the database dialect and schema. Database execution requires your existing authorization.

## Workflow

1. Read table definitions, keys, nullability and the intended reporting grain. Ask for a missing join key rather than inventing it.
2. Map each requested metric to its source and aggregation. Check join cardinality before summing money or counts.
3. Write a single SELECT or read-only CTE using bound parameters. Keep identifiers fixed from the schema.
4. Check syntax with the available dialect parser or EXPLAIN in an authorized read-only session. Report when no database check ran.
5. Show a tiny input/output example and call out null handling, timezone and duplicate-row risks.

## Worked example

Read `examples/input.txt` and `examples/expected.txt` before adapting the workflow.

## Acceptance checks

Use only supplied identifiers; preserve cents as integers; parameterize status; include deterministic tie ordering.

## Limits

A plausible query is not a verified report. Permission checks, performance and tenant filters must be confirmed against the actual database.

Worked example included. Model-specific performance and vendor compatibility have not been benchmarked.
