Skip to main content

rego_parse_error: unexpected string token

This parser error is raised when the Rego parser encounters an unexpected string token. This is typically caused by a missing keyword or operator.

parsingrego_parse_errorunexpected string token


A simple example of a policy that contains this error follows, note the missing == after input.roles:

package policy

import rego.v1

allow if {
input.role "admin"

The code above will raise the following error:

1 error occurred: policy.rego:6: rego_parse_error: unexpected string token: expected \n or ; or }
input.roles "admin"

How To Fix It

While the fix for this error depends on other elements on the line of Rego in question, the error message will always point to the location of the error to get you started.

Typically, the fix it to determine the intended functionality of the line in question and add a missing keyword or operator. Often ==/!=, or in.


For questions, discussions and announcements related to OPA, or Styra products, services and open source projects, please join the Styra Community on Slack.