Compile (partially evaluate) a query on OPA
opa_compile_queryCompile Rego queries or translate OPA policy rules into residual queries and target data filters such as SQL WHERE clauses, UCAST trees, or Lucene queries.
Instructions
Send a query to the OPA server's /v1/compile endpoint for partial evaluation. Returns the residual query -- what remains after substituting in everything that's known. With target, it instead translates the rule at path into a data filter: a SQL WHERE clause (postgresql, mysql, sqlserver, sqlite), a UCAST tree (for Prisma, LINQ or your own code), or a Lucene query for Solr, through /v1/compile/{path}. The rule must be loaded on the server, and its unknowns, usually the rows searched, come from unknowns or a compile METADATA annotation. A SQL query of "", a UCAST query of {} or a Lucene query of : means every row matches; matchesNothing means none does, or no rule exists at path, which OPA answers the same way. A policy the target cannot express returns EVAL_ERROR with each expression at fault in details.errors; a target the server is too old for returns OPA_VERSION_UNSUPPORTED (Lucene needs OPA 1.23).
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "opa_compile_query"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | With `target`: the filter rule under `data.`, e.g. "filters/include" or "filters.include", or its segments as an array. | |
| input | No | The known part of the input. OPA does not use a value at or under an unknown, so with the default `unknowns` of ["input"] an input is refused: name the unknown parts instead, e.g. ["input.region"]. | |
| query | No | Rego query to compile, e.g. "data.rbac.allow == true". Required without `target`; not used with it. | |
| target | No | Translate the rule at `path` into a data filter of this kind. `multitarget` returns several at once, one per entry in `dialects`. | |
| dialects | No | With `target: "multitarget"`: the filters to return. Lucene is not one. | |
| maskRule | No | With `target`: the rule that produces column masks, e.g. "data.filters.masks". Overrides a `mask_rule` annotation. | |
| unknowns | No | Refs to treat as unknown. Default ["input"] for a query; with `target`, none beyond what the policy declares, e.g. ["input.fruits"] for the table searched. | |
| tableMappings | No | With a SQL target: table and column names to write instead of the ones in the policy, per dialect, e.g. {"postgresql": {"fruits": {"$self": "f", "colour": "col"}}}. |