Skip to main content
Glama

Format Rego

rego_format
Read-onlyIdempotent

Format Rego source code using opa fmt, returning canonical output and a changed flag. Warns or blocks on unsafe OPA versions to prevent corruption.

Instructions

Format Rego source code using opa fmt. Returns the formatted source and a changed flag indicating whether the input was already canonical. When the source uses string interpolation ($"..." or $... syntax) and OPA v1.12.0 or v1.12.1 is detected, the tool warns about or blocks formatting due to a known OPA bug that corrupts { escape sequences (fixed in OPA v1.12.2).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceYesRego source code to format.
v0CompatibleNoFormat a policy written in pre-1.0 Rego as pre-1.0 Rego (`--v0-compatible`), leaving its syntax as it is. OPA 1.x otherwise refuses it. To convert it to Rego v1 instead, use `rego_migrate_v1`.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.7.0
    • addedInput schema / properties / v0Compatible
      Added value: +{
      +  "description": "Format a policy written in pre-1.0 Rego as pre-1.0 Rego (`--v0-compatible`), leaving its syntax as it is. OPA 1.x otherwise refuses it. To convert it to Rego v1 instead, use `rego_migrate_v1`.",
      +  "type": "boolean"
      +}
  2. Added
  3. Removedv0.1.5
  4. Addedv0.1.2
  5. Removedv0.1.1
  6. First observedv0.1.0

TDQS

A3.8/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true, idempotentHint=true, and destructiveHint=false. The description adds useful behavioral context by explaining the `changed` flag and the OPA v1.12.0/v1.12.1 bug warning/blocking behavior. The phrase 'warns about or blocks' is slightly ambiguous, but it still discloses an important edge case beyond the annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences with no filler. It front-loads the core purpose, then covers return behavior and the notable OPA bug edge case. Every sentence earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description explains the return value (`formatted source` and `changed` flag) and the important version-specific bug behavior, which is sufficient for most calls. It is slightly incomplete because it does not clarify the distinction from `rego_format_write` and leaves the warn-vs-block behavior ambiguous, but overall it covers the key operational details.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both `source` and `v0Compatible` clearly. The tool description adds no additional parameter-level meaning beyond what the schema provides, so the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool formats Rego source code using `opa fmt` and returns the formatted source plus a `changed` flag. This is a specific verb+resource and is easy to understand, but it does not explicitly distinguish itself from the sibling `rego_format_write` or other formatting-related tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for formatting Rego source, and the `v0Compatible` parameter description explicitly routes conversion to Rego v1 to `rego_migrate_v1`. However, there is no general guidance on when to choose this tool over `rego_format_write`, `rego_fix`, or other alternatives, so usage context is only partially addressed.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.