Skip to main content

PromQL Formatter

Format and validate PromQL (Prometheus Query Language) expressions — consistent indentation and line-breaking for metric selectors, label matchers, functions, binary/aggregation operators, and by/without/on/group_left clauses. Optionally wraps the result as a Prometheus recording rule. Runs entirely in your browser.

Input

Drop a file or browse
One file · text
Or

Formatting Options

Function calls and binary operators wrap when a line would exceed this width.

Output

Validation
Issue
No data yet
Formatted PromQL
 
Was this helpful?

Guides

Paste a PromQL (Prometheus Query Language) expression and get back a cleanly formatted, consistently indented query — metric selectors, label matchers, functions, binary and aggregation operators, and by/without/on/ignoring/group_left/group_right clauses all get normalized spacing and predictable line-breaking. A quick validation pass flags unbalanced brackets, an unterminated string, and malformed label matchers or range-vector subscripts. Everything runs locally in your browser.

How to use it

  1. Paste your PromQL query, or upload a .promql/.txt file.
  2. Choose 2 spaces, 4 spaces, or Tab for indentation, and a Max Line Length — lines longer than this wrap at aggregation clauses, function arguments, label matchers, and low-precedence binary keywords (and/or/unless).
  3. Turn on Always break onto separate lines to force multi-line output regardless of width — handy for reviewing a dense query in a pull request diff.
  4. Turn on Wrap output as a Prometheus recording rule to get a ready-to-paste - record: ... \n expr: ... YAML block instead of a bare expression; give it a valid recording rule name (a-z, 0-9, _, :).
  5. Check the Validation panel for any syntax issues, then copy or download the formatted result.

What it formats

  • Metric selectors and label matchers ({job="api", env=~"prod|staging"}), aligning matcher pairs on their own line once a matcher gets long.
  • Range-vector subscripts ([5m], [5m:1m] subqueries) and offset/@ modifiers.
  • Function calls (rate(...), histogram_quantile(...)) and aggregation operators (sum, avg, topk, …) with by/without clauses.
  • Binary operators (arithmetic, comparison, and the and/or/unless/atan2 keyword operators) and vector matching (on/ignoring/group_left/group_right).

Does it validate the query semantically?

No — this checks syntax, not whether a metric or label actually exists in your Prometheus instance. It flags structural problems: unbalanced ()[]{}, an unterminated string, a label matcher missing its operator or quoted value, and an invalid range-vector subscript. For real query execution, use promtool query or your Prometheus instance's own query API.

Is my query uploaded anywhere?

No. Tokenizing, parsing, and formatting all run locally in your browser; your PromQL source is never sent to a server.

Need to work with other observability config formats?

See the Apache HTTPD Config Formatter or the Access Log Formatter for other server-side text formats, or the GraphQL Schema Formatter for a different query-language formatter.

promqlprometheusformattervalidatormonitoringobservabilityquery

Use it from code

From 3 credits per call

REST API

curl -X POST https://api.iotools.cloud/v1/tool/promql-formatter \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "promqlInput": "sum by (job, instance) (rate(http_requests_total…",
    "indentSize": "2",
    "maxLineLength": "100",
    "forceMultiline": "",
    "wrapRecordingRule": "",
    "recordingRuleName": "my:metric:name"
  }'

Swap in your own key from your account. The tool's fields are the body — no wrapper.

Ask an AI agent

Use the IOTools `promql-formatter` tool (PromQL Formatter) on this input:

YOUR_INPUT_HERE

Paste this at any agent connected to the IOTools MCP server, then add your input.

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.