Skip to main content
Glama

Diff two Rego policies

rego_policy_diff

Evaluate the same query against two Rego policies in parallel and report whether results match, with raw outputs and differing paths to verify refactors or locate divergences.

Instructions

Evaluate the same query against two policies (or two versions of the same policy) and compare the results. Both evaluations run in parallel. Returns equal: true/false, the raw result from each side, and changedPaths -- the dot/bracket paths that differ. Useful for verifying that a refactor preserves behavior, or understanding exactly where two policies diverge. Each side takes either inline source (sourceA/sourceB) or a file/directory path (pathA/pathB). The same input and query are used for both evaluations; pass inputs to compare on many input documents in one call, and dataPaths to load the data the policies read.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputNoInline input document (JSON). Mutually exclusive with inputPath.
pathANoFile or directory path for policy A. Must be inside an allowed root. Mutually exclusive with sourceA.
pathBNoFile or directory path for policy B. Must be inside an allowed root. Mutually exclusive with sourceB.
queryYesThe query to evaluate against both policies, e.g. "data.example.allow".
inputsNoUp to 50 input documents to compare the two policies on, in place of `input`/`inputPath`. The result is `batch`, one entry per input in order, and `differing` counts the inputs on which the policies disagree. A policy that does not compile fails the call once; a runtime error on one input is reported in its entry.
sourceANoInline Rego source for policy A. Mutually exclusive with pathA.
sourceBNoInline Rego source for policy B. Mutually exclusive with pathB.
dataPathsNoAdditional data or policy paths loaded for both evaluations. Each must be inside an allowed root.
inputPathNoPath to a JSON input file. Must be inside an allowed root. Mutually exclusive with input.
v0CompatibleANoRead policy A as Rego v0 (`--v0-compatible`), the syntax before OPA 1.0. Set this and leave `v0CompatibleB` off to compare a legacy policy with its migrated copy.
v0CompatibleBNoRead policy B as Rego v0 (`--v0-compatible`).

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.9.0
    • addedInput schema / properties / inputs
      Added value: +{
      +  "description": "Up to 50 input documents to compare the two policies on, in place of `input`/`inputPath`. The result is `batch`, one entry per input in order, and `differing` counts the inputs on which the policies disagree. A policy that does not compile fails the call once; a runtime error on one input is reported in its entry.",
      +  "items": {},
      +  "maxItems": 50,
      +  "minItems": 1,
      +  "type": "array"
      +}
  2. Changed2 schema fields changedv0.8.0
    • addedInput schema / properties / v0CompatibleA
      Added value: +{
      +  "description": "Read policy A as Rego v0 (`--v0-compatible`), the syntax before OPA 1.0. Set this and leave `v0CompatibleB` off to compare a legacy policy with its migrated copy.",
      +  "type": "boolean"
      +}
    • addedInput schema / properties / v0CompatibleB
      Added value: +{
      +  "description": "Read policy B as Rego v0 (`--v0-compatible`).",
      +  "type": "boolean"
      +}
  3. Addedv0.1.13

TDQS

A4.3/5.0
Behavior4/5

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

With annotations present, it adds meaningful behavioral context beyond them: the two evaluations 'run in parallel,' and it spells out the return shape (`equal`, per-side raw result, `changedPaths`). It also frames the source-vs-path requirement per side. It does not discuss error handling or permissions, keeping it below a 5.

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

Conciseness4/5

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

Front-loaded with the core purpose and return contract before drilling into parameter mechanics. Five dense sentences convey a lot without filler, though it is slightly long and could trim the parallel-evaluation aside.

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?

No output schema exists, but the description compensates by naming the return fields (`equal`, `changedPaths`, batch behavior). For an 11-parameter tool it covers the essential mechanics; only error/authorization behavior is left unaddressed.

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

Parameters4/5

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

Schema coverage is 100% so the baseline is 3, but the description adds real meaning: it explains the A/B pairing (sourceA/sourceB vs pathA/pathB), that the same input and query are reused for both sides, and that `inputs` batches many input documents while `dataPaths` supplies the read data.

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

Purpose5/5

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

States specific verbs (evaluate, compare, diff) and the exact resource (two Rego policies / two versions of one). It distinguishes itself from siblings like rego_eval by making the two-policy comparison the whole point, so an agent can tell it apart without opening the schema.

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

Usage Guidelines4/5

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

Gives clear usage context: 'verifying that a refactor preserves behavior' or 'understanding exactly where two policies diverge.' It never names an alternative (e.g., use rego_eval for a single policy) or states when not to use it, so it stops short of the explicit routing a 5 would require.

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