Skip to content

Evaluate Core IR JSON Policy

Evaluate a policy expressed as a Core IR JSON object directly, without CNL parsing or compilation. Use this endpoint when your application manages its own compilation pipeline and sends pre-compiled policy representations to the engine.

Endpoint

POST /api/v1/policies/evaluate-json

Required Role

MEMBER

Headers

HeaderValueRequired
AuthorizationBearer <token>Yes
Content-Typeapplication/jsonYes
X-Tenant-IDTenant identifier stringYes

Request Body

json
{
  "policy": "string (Core IR JSON)",
  "context": {}
}
FieldTypeRequiredDescription
policystringYesA JSON-encoded string containing the Core IR representation of the policy. This is the serialized form produced by the Aster compiler's IR emission stage. The engine deserializes and executes this IR directly, bypassing all CNL parsing steps.
contextobjectYesA single object whose keys map to the declared parameter names of the entry-point function in the Core IR.

Core IR JSON Format

The policy field must be a string-serialized JSON object conforming to the Core IR schema. A minimal example with a single function:

json
{
  "moduleName": "Discount",
  "functions": [
    {
      "name": "calculate",
      "params": [{ "name": "order", "type": "Order" }],
      "rules": [
        {
          "condition": { "op": "gt", "left": { "ref": "order.total" }, "right": { "lit": 100 } },
          "result": { "lit": 10 }
        },
        {
          "condition": null,
          "result": { "lit": 0 }
        }
      ]
    }
  ]
}

When embedding this as the policy field in the request, the object must be JSON-stringified (i.e. the entire object becomes a string value).

Response Body

json
{
  "result": "<any>",
  "executionTimeMs": 0,
  "error": null,
  "decisionTrace": null
}
FieldTypeDescription
resultanyThe value returned by the entry-point function in the Core IR.
executionTimeMsnumberWall-clock time in milliseconds from IR deserialization to response dispatch.
errorstring | nullIR deserialization or runtime error message; null on success.
decisionTraceobject | nullAlways null for this endpoint. Tracing is not supported for Core IR evaluation.

HTTP Status Codes

StatusMeaning
200 OKEvaluation attempted. Check error for IR parsing or runtime failures.
400 Bad RequestMalformed request body, invalid Core IR JSON, or missing required fields.
401 UnauthorizedMissing or invalid bearer token.
403 ForbiddenToken is valid but the caller lacks the MEMBER role.
500 Internal Server ErrorUnexpected engine failure.

Examples

bash
curl -X POST https://policy.aster-lang.dev/api/v1/policies/evaluate-json \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -H "X-Tenant-ID: acme-corp" \
  -d '{
    "policy": "{\"moduleName\":\"Discount\",\"functions\":[{\"name\":\"calculate\",\"params\":[{\"name\":\"order\",\"type\":\"Order\"}],\"rules\":[{\"condition\":{\"op\":\"gt\",\"left\":{\"ref\":\"order.total\"},\"right\":{\"lit\":100}},\"result\":{\"lit\":10}},{\"condition\":null,\"result\":{\"lit\":0}}]}]}",
    "context": {
      "order": { "total": 150 }
    }
  }'
js
// Build the Core IR object
const coreIR = {
  moduleName: 'Discount',
  functions: [
    {
      name: 'calculate',
      params: [{ name: 'order', type: 'Order' }],
      rules: [
        {
          condition: { op: 'gt', left: { ref: 'order.total' }, right: { lit: 100 } },
          result: { lit: 10 },
        },
        {
          condition: null,
          result: { lit: 0 },
        },
      ],
    },
  ],
};

const response = await fetch(
  'https://policy.aster-lang.dev/api/v1/policies/evaluate-json',
  {
    method: 'POST',
    headers: {
      Authorization: 'Bearer <token>',
      'Content-Type': 'application/json',
      'X-Tenant-ID': 'acme-corp',
    },
    body: JSON.stringify({
      // Core IR must be serialized as a string
      policy: JSON.stringify(coreIR),
      context: {
        order: { total: 150 },
      },
    }),
  }
);

const data = await response.json();
// data.result → 10

Example Response

json
{
  "result": 10,
  "executionTimeMs": 3,
  "error": null,
  "decisionTrace": null
}

Released under the MIT License.