Skip to content

Evaluate Policy

Evaluate a deployed policy by module and function name. The policy must already be deployed to the engine before it can be called through this endpoint.

Endpoint

POST /api/v1/policies/evaluate

Required Role

MEMBER

Headers

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

Request Body

json
{
  "policyModule": "string",
  "policyFunction": "string",
  "context": [{}]
}
FieldTypeRequiredDescription
policyModulestringYesThe fully-qualified module name as declared in the CNL source (e.g. "Loan.Approval").
policyFunctionstringYesThe function name within the module to invoke (e.g. "isEligible").
contextarray<object>YesAn ordered list of argument objects passed positionally to the policy function. The structure of each object must match the parameter schema declared in the policy. Pass an empty array [] for zero-argument functions.

Response Body

json
{
  "result": "<any>",
  "executionTimeMs": 0,
  "error": null,
  "decisionTrace": null
}
FieldTypeDescription
resultanyThe value returned by the policy function. The type matches the declared return type of the function (boolean, number, string, or object).
executionTimeMsnumberWall-clock time in milliseconds from request receipt to response dispatch.
errorstring | nullHuman-readable error message if evaluation failed; null on success.
decisionTraceobject | nullStructured trace of rule evaluation steps. Always null for this endpoint. Use /evaluate-source?trace=true to obtain a trace.

HTTP Status Codes

StatusMeaning
200 OKEvaluation completed. Check error field — a non-null value indicates a policy-level failure while the HTTP call itself succeeded.
400 Bad RequestMalformed request body or missing required fields.
401 UnauthorizedMissing or invalid bearer token.
403 ForbiddenToken is valid but the caller lacks the MEMBER role.
404 Not FoundNo deployed policy found matching policyModule + policyFunction.
500 Internal Server ErrorUnexpected engine failure.

Examples

bash
curl -X POST https://policy.aster-lang.dev/api/v1/policies/evaluate \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -H "X-Tenant-ID: acme-corp" \
  -d '{
    "policyModule": "Loan.Approval",
    "policyFunction": "isEligible",
    "context": [
      {
        "applicantAge": 30,
        "annualIncome": 75000,
        "creditScore": 720,
        "requestedAmount": 25000
      }
    ]
  }'
js
const response = await fetch(
  'https://policy.aster-lang.dev/api/v1/policies/evaluate',
  {
    method: 'POST',
    headers: {
      Authorization: 'Bearer <token>',
      'Content-Type': 'application/json',
      'X-Tenant-ID': 'acme-corp',
    },
    body: JSON.stringify({
      policyModule: 'Loan.Approval',
      policyFunction: 'isEligible',
      context: [
        {
          applicantAge: 30,
          annualIncome: 75000,
          creditScore: 720,
          requestedAmount: 25000,
        },
      ],
    }),
  }
);

const data = await response.json();
// data.result  → true | false | number | string | object
// data.error   → null on success

Example Response

json
{
  "result": true,
  "executionTimeMs": 4,
  "error": null,
  "decisionTrace": null
}

Released under the MIT License.