Create Rule
lexq_rules_createCreate a rule in a DRAFT version. It goes last in priority order; lexq_rules_reorder changes the order.
An action's targetVar must be a registered fact (ACT-032 otherwise). Keys a rule only reads (condition fields, refVar) may stay unregistered. Actions must use facts in the data types they are registered with. MUTATE_FACT's targetVar must be a NUMBER fact, and so must its refVar if that key is registered (ACT-035 otherwise). SET_FACT's value must match the data type of its targetVar (ACT-036 otherwise). For example, "10" does not match a NUMBER fact. A null value matches any data type.
Condition: { type: "SINGLE", field, operator, value, valueType } or { type: "GROUP", operator: "AND"|"OR", children: [...] } Value types: STRING, NUMBER, BOOLEAN, LIST_STRING, LIST_NUMBER Limits: 25 SINGLE conditions per rule (GROUP nodes do not count), 10 levels of nesting below the root, 100 rules per version. Value limits: every value in a condition or an action has the same limits as a value in an execution call. A list holds up to 1000 items, text up to 4096 characters, and a number up to 34 digits before and 34 after the decimal point. Saving or publishing a rule with a value over a limit fails with P-064, and the message gives the value's path.
Operators that work on each fact type:
STRING: EQUALS, NOT_EQUALS, CONTAINS (substring), IN, NOT_IN
NUMBER: EQUALS, NOT_EQUALS, GREATER_THAN, GREATER_THAN_OR_EQUAL, LESS_THAN, LESS_THAN_OR_EQUAL, IN, NOT_IN
BOOLEAN: EQUALS, NOT_EQUALS
LIST_STRING, LIST_NUMBER: HAS_ANY, HAS_ALL, HAS_NONE IN and NOT_IN test whether the fact's value is in the array. HAS_ANY, HAS_ALL and HAS_NONE match when the fact's list holds at least one, all, or none of the array's values. The array holds values of the fact's type, or for a list fact, of its element type. Example: { "type": "SINGLE", "field": "userTags", "operator": "HAS_ANY", "value": ["VIP","GOLD"], "valueType": "LIST_STRING" }
Actions: [{ type, parameters }]
MUTATE_FACT: { targetVar, operator: "ASSIGN"|"ADD"|"SUB"|"MUL"|"DIV", method: "PERCENTAGE"|"AMOUNT", operand: number, refVar?, rounding? } Reads and writes targetVar. The request must send it (P-015 otherwise), and it must hold a number when the action runs. operand may be negative, and a percent may be over 100. AMOUNT PERCENTAGE (base = refVar, or targetVar when omitted) ASSIGN targetVar = operand targetVar = base × operand/100 ADD targetVar += operand targetVar += base × operand/100 SUB targetVar -= operand targetVar -= base × operand/100 MUL targetVar *= operand targetVar *= (operand/100 + 1) DIV targetVar /= operand invalid refVar is allowed only with PERCENTAGE and ASSIGN, ADD or SUB. DIV with AMOUNT needs a nonzero operand. rounding: { scale: integer (0..34), mode?: "UP"|"DOWN"|"CEILING"|"FLOOR"|"HALF_UP"|"HALF_DOWN"|"HALF_EVEN" }. mode defaults to HALF_UP. Without rounding, the result keeps at most 34 significant digits and at most 34 digits after the decimal point, rounded half-even. At execution, a result or {targetVar}__delta with more than 34 digits before the decimal point fails the call with ACT-034. Send smaller values or change the calculation. See https://docs.lexq.io/guides/policy-rules#mutate_fact-%E2%80%94-with-rounding for organizations that use Fail-open.
SET_FACT: { targetVar, value }, where value matches the data type of targetVar. The request does not have to send targetVar.
BLOCK: { reason? } sets isBlocked to true and blockReason to the reason, or "Policy Violation" without one. It does not stop later actions or rules; the caller enforces the block. Only BLOCK writes these two keys: a SET_FACT or MUTATE_FACT targeting either is rejected (ACT-033).
Every condition is checked against the input facts before any action runs, so a condition never sees a value an action writes in the same request. The winning rules' actions then run in priority order, each on the values the actions before it left.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"groupId": "<groupId>",
"versionId": "<versionId>",
"rule": "<rule>"
},
"name": "lexq_rules_create"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rule | Yes | JSON string of CreateRuleRequest: { name, condition, actions, mutexGroup?, mutexMode?, mutexStrategy?, mutexLimit?, isEnabled? } | |
| groupId | Yes | Policy group ID | |
| versionId | Yes | Version ID |