Skip to main content
Glama

Migrate Rego to v1 syntax

rego_migrate_v1

Migrate Rego v0 source to Rego v1: rename reserved rules, replace removed built-ins, format syntax with opa fmt, and validate migration with opa check and optional equivalence tests.

Instructions

Migrate Rego v0 source to Rego v1. First renames what v1 reserves (a rule called contains, every, if or in, and every reference to it in the module) and replaces built-ins v1 removed: re_match and net.cidr_overlap by their v1 names, and all, any, set_diff and the cast_* family by a helper function appended to the module that returns exactly what the built-in did, so behaviour does not change. re_match and net.cidr_overlap get such a helper too where the rename would change behaviour: the module mocks one spelling with with while calling both, or binds regex or net itself. Then opa fmt --rego-v1 converts the syntax (if, contains, import rego.v1) and opa check validates the result. rewrites lists each change by line and notes says why; a renamed rule must also be renamed in any other module that uses it. Pass inputs to evaluate the original as v0 and the result as v1 against each and compare every rule of the package, and queries to compare expressions too, such as calls to its functions; equivalence reports any difference. Evaluating runs the policy, http.send included. Returns the migrated source even when check finds remaining errors. A source that parses only as Rego v1 is returned unchanged; one that parses as both, such as v1 that imports rego.v1, is reformatted like any other. If the source parses as neither, returns INVALID_REGO with opa's own message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputsNoUp to 20 input documents to check the migration against. The original is evaluated as Rego v0 and the migrated policy as Rego v1 against each one, every rule of the package that is not a function is compared by value and by type, and `equivalence` reports any that differ.
sourceYesRego v0 source to migrate to Rego v1 syntax. Rules named with a word v1 reserves are renamed and built-ins v1 removed are replaced before `opa fmt --rego-v1` converts the syntax; any remaining issues are returned in `errors` so you can resolve them manually.
queriesNoUp to 10 Rego expressions to compare on each of `inputs` as well. A function has no value without arguments, so this is how functions are compared: `data.lib.names.label_ok(input.name, input.label)`. An expression that names a rule this tool renames, as `data.<package>.<rule>`, reaches it under its new name on the migrated side.
dataPathsNoData files (JSON or YAML), or directories of them, to load on both sides when comparing `inputs`, for a policy that reads `data`. Without them every such reference is undefined on both sides, and they agree about nothing. A `.rego` module found there is loaded too, so it has to parse as both v0 and v1. Each path must be inside an allowed root.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.9.0
    • addedInput schema / properties / dataPaths
      Added value: +{
      +  "description": "Data files (JSON or YAML), or directories of them, to load on both sides when comparing `inputs`, for a policy that reads `data`. Without them every such reference is undefined on both sides, and they agree about nothing. A `.rego` module found there is loaded too, so it has to parse as both v0 and v1. Each path must be inside an allowed root.",
      +  "items": {
      +    "type": "string"
      +  },
      +  "type": "array"
      +}
  2. Changed2 schema fields changedv0.8.0
    • changedInput schema / properties / inputs / description
      Previous value: -"Up to 20 input documents to check the migration against. The original is evaluated as Rego v0 and the migrated policy as Rego v1 against each one, every rule of the package is compared by value and by type, and `equivalence` reports any that differ."New value: +"Up to 20 input documents to check the migration against. The original is evaluated as Rego v0 and the migrated policy as Rego v1 against each one, every rule of the package that is not a function is compared by value and by type, and `equivalence` reports any that differ."
    • addedInput schema / properties / queries
      Added value: +{
      +  "description": "Up to 10 Rego expressions to compare on each of `inputs` as well. A function has no value without arguments, so this is how functions are compared: `data.lib.names.label_ok(input.name, input.label)`. An expression that names a rule this tool renames, as `data.<package>.<rule>`, reaches it under its new name on the migrated side.",
      +  "items": {
      +    "minLength": 1,
      +    "type": "string"
      +  },
      +  "maxItems": 10,
      +  "minItems": 1,
      +  "type": "array"
      +}
  3. Changed2 schema fields changedv0.7.0
    • addedInput schema / properties / inputs
      Added value: +{
      +  "description": "Up to 20 input documents to check the migration against. The original is evaluated as Rego v0 and the migrated policy as Rego v1 against each one, every rule of the package is compared by value and by type, and `equivalence` reports any that differ.",
      +  "items": {},
      +  "maxItems": 20,
      +  "minItems": 1,
      +  "type": "array"
      +}
    • changedInput schema / properties / source / description
      Previous value: -"Rego v0 source to migrate to Rego v1 syntax. `opa fmt --rego-v1` auto-fixes reserved keywords and adds `import rego.v1`; any remaining issues are returned in `errors` so you can resolve them manually."New value: +"Rego v0 source to migrate to Rego v1 syntax. Rules named with a word v1 reserves are renamed and built-ins v1 removed are replaced before `opa fmt --rego-v1` converts the syntax; any remaining issues are returned in `errors` so you can resolve them manually."
  4. Addedv0.1.13

TDQS

A3.9/5.0
Behavior5/5

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

Goes well past the annotations: it discloses that equivalence checking actually evaluates the policy with network effects ('Evaluating runs the policy, `http.send` included'), that the migrated source is returned even when check finds errors, the INVALID_REGO failure mode with opa's own message, and the 'allowed root' constraint on dataPaths. This is exactly the side-effect and failure-mode context the readOnlyHint=false / openWorldHint=true annotations imply but do not explain.

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

Conciseness3/5

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

The opening sentence front-loads the purpose correctly, but the remainder is one dense, run-on block of clauses covering renames, helpers, formatting, equivalence, side effects and error handling without any structural separation. Most sentences do earn their place given the tool's complexity, yet the wall-of-text delivery makes it harder to scan than it needs to be.

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

Completeness5/5

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

For a complex, side-effecting migration tool with no output schema, the description still covers return shape (rewrites, notes, equivalence), idempotency (v1-only source returned unchanged), and the parse-failure path. Nothing an agent needs in order to call it correctly appears to be missing.

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 inputs, source, queries and dataPaths thoroughly, and the description largely restates that same material (20-input cap, v0-vs-v1 comparison, renamed-rule resolution). It adds a little cross-cutting meaning, such as the warning that a renamed rule must also be renamed in other modules, but not enough to exceed the baseline when the schema does the heavy lifting.

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 states a precise verb+resource (migrate Rego v0 source to Rego v1) and enumerates exactly which renames, built-in replacements, formatting and validation steps occur. It is unmistakably distinct in behavior, but it never names or contrasts a sibling (rego_fix, rego_format, rego_check), so an agent must infer the boundary itself.

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?

It gives solid conditional guidance for the optional parameters ('Pass inputs to evaluate...', 'queries to compare expressions too'), which tells the agent when those knobs matter. It never says when to choose this tool over the adjacent format/fix/check siblings, so the when-to-use decision against alternatives is left implicit.

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