---
title: "Use this when a user pastes messy or minified SQL and wants it pretty-printed into a readable, canonical layout, or wants keyword casing normalized."
method: POST
path: "/v1/format_sql"
tags: ["developer"]
---

# Use this when a user pastes messy or minified SQL and wants it pretty-printed into a readable, canonical layout, or wants keyword casing normalized.

`POST /v1/format_sql`

## Request

- Base URL: `https://api.clean.tools`
- URL: `https://api.clean.tools/v1/format_sql`
- Auth: none declared

Use this when a user pastes messy or minified SQL and wants it pretty-printed into a readable, canonical layout, or wants keyword casing normalized. Deterministic: same input, same output. Each clause keyword (SELECT, FROM, WHERE, GROUP BY, ...) goes on its own line with its arguments indented beneath it, commas break columns onto new lines, JOIN/AND/OR start fresh lines, and short parenthesised groups stay inline. Optional dialect hint affects identifier quoting (e.g. tsql [brackets]); indent is a spaces count or "tab" (default 2); keywordCase is upper/lower/preserve (default upper). Example: "select id from t" -> formatted "SELECT\n  id\nFROM\n  t". Returns an error for empty or oversized (>200000 chars) input.

## Request body

- object
  - `sql` string, required: The SQL query text to format. Required, non-empty.
  - `dialect` 'sql' | 'postgresql' | 'mysql' | 'tsql' | 'bigquery' | 'sqlite': SQL dialect hint (affects identifier quoting, e.g. T-SQL [brackets]). Optional; defaults to standard 'sql'.
  - `indent` union: Indentation: a number of spaces (e.g. 2 or 4) or the string "tab" for tab characters. Optional; defaults to 2.
    - integer
    - '2' | '4' | 'tab'
  - `keywordCase` 'upper' | 'lower' | 'preserve': How to case reserved keywords/functions: UPPER, lower, or preserve as-is. Optional; defaults to 'upper'.

## Response `200`

Structured tool result.

- object
  - `tool` string
  - `result` object
    - `formatted` string, required: The reformatted SQL as a single text string, with newlines and indentation applied. Trailing whitespace and leading/trailing blank lines are stripped.

## Other responses

- `400`: Invalid input or the tool reported an error.
- `413`: Request body exceeds the 128 KB limit.
- `429`: Rate limit exceeded; the response carries Retry-After and RateLimit-* headers — honor them and add jitter.

---

[API](https://skmtc.dev/clean/apis/clean-tools-api.md) · [All operations](https://skmtc.dev/clean/apis/clean-tools-api/llms.txt) · [OpenAPI document](https://skmtc.dev/clean/apis/clean-tools-api/revisions/a24a01d2833c?raw)
