Visual DMN & FEEL Engine
LatticeDX decouples volatile business rules from workflow DAG topology through a zero-eval Decision Model and Notation (DMN) engine in @latticedx/plugin-dxos-studio. Analysts and platform engineers author decision tables in Control Studio or via dxosDmn, simulate draft rules without database writes, and feed deterministic outputs into logic.dmn nodes inside LatticeFlow v2.
- Role
- Safe AST condition parser & matcher without eval()
- Package / Port
- @latticedx/plugin-dxos-studio · dmn-engine.js
- Protocol
- Zero-Eval AST Matcher · Object.hasOwn
- Payload / Schema
- ALLOWED_OPERATORS (11 operators · prototype-safe)
- Responsibilities
- Compiles string or JSON predicates to { op, value }, reads inputs via Object.hasOwn, and collects candidate rows matching all when columns.
Data Model & Validation Caps
Each decision table is stored in latticeDecisionTables under PostgreSQL 16 FORCE ROW LEVEL SECURITY scoped by organizationId. Records are uniquely indexed per tenant on (organizationId, tableKey) via uidx_lattice_dmn_org_key.
| Parameter | Type | Default | Description |
|---|---|---|---|
organizationIdrequired | string | — | Tenant identifier owning the decision table; must match the active RLS session context. |
tableKeyrequired | string | — | Unique key within the tenant matching /^[a-zA-Z0-9_-]{2,80}$/. |
namerequired | string | — | Human-readable table title (capped at 160 characters). |
description | string | — | Operational rule scope description (capped at 500 characters). |
hitPolicy | string | FIRST | Match aggregation policy: FIRST, UNIQUE, COLLECT, or PRIORITY. |
inputsJsonrequired | jsonb | — | Array of 1 to 50 input declarations { name, type?, label? }. |
outputsJsonrequired | jsonb | — | Array of 1 to 50 output declarations { name, type?, label? }. |
rulesJsonrequired | jsonb | — | Array of up to 500 rules { when, then, priority?, description? }. |
version | integer | 1 | Monotonically incremented revision number managed by dxosDmn:saveTable. |
published | boolean | true | Publication state flag for studio lifecycle tracking. |
active | boolean | true | Only tables with active = true can be evaluated by tableKey. |
Validation guards execute before persistence or draft simulation:
| Constraint | Cap / Pattern | Error Code |
|---|---|---|
tableKey syntax | ^[a-zA-Z0-9_-]{2,80}$ | 400 DMN_TABLE_KEY_INVALID |
Field identifier syntax (inputsJson, outputsJson, when, then) | ^[a-zA-Z0-9_.-]{1,64}$ | 400 DMN_SCHEMA_INVALID / DMN_RULE_INVALID |
inputsJson and outputsJson cardinality | 1 to 50 fields per array | 400 DMN_SCHEMA_INVALID |
rulesJson cardinality | Maximum 500 rules per table | 400 DMN_RULE_INVALID |
Blocked prototype keys (FORBIDDEN_KEYS) | __proto__, constructor, prototype | 400 DMN_SCHEMA_INVALID / DMN_RULE_INVALID |
Rule-level description length | Truncated at 255 characters | Normalized on save |
During fact evaluation, evaluateDecisionTable reads input keys exclusively via Object.hasOwn(ctxObj, inputKey), preventing prototype-chain lookup leaks.
Four Hit Policies (HIT_POLICIES)
evaluateDecisionTable in dmn-engine.js supports four deterministic hit policies when evaluating rulesJson:
| Hit Policy | Evaluation Semantics | Output Shape | Conflict & Edge Behavior |
|---|---|---|---|
FIRST | Evaluates rules top-to-bottom and stops on the first match | Single result and outputs object plus matchedRuleIndex | Returns matched: false, matchedRuleIndex: -1, result: null when nothing matches |
UNIQUE | Evaluates every rule to verify mutual exclusivity | Single result, outputs, results: [only.outputs], matchedRuleIndex | Throws HTTP 409 DMN_UNIQUE_POLICY_VIOLATION if more than one rule matches |
COLLECT | Evaluates every rule and aggregates all matching rule outputs in declaration order | results: [...] array of then objects plus matchedRules | Returns matched: false, results: [] when no rule matches |
PRIORITY | Evaluates every rule and sorts matches descending by numeric priority (or rank) | Top rule result / outputs, results: [top.outputs], sorted matchedRules | Ties break by ascending ruleIndex; omitted priority defaults to 0 |
Complete FEEL Expression Reference
Every when condition is normalized into { op, value } via normalizeConditionSpec and parseStringConditionSpec. No eval() or new Function() is ever invoked. Rules accept both shorthand FEEL strings and structured JSON condition objects.
| Canonical Operator | Accepted Aliases | FEEL Shorthand String | Structured JSON | Evaluation Semantics |
|---|---|---|---|---|
eq | ==, ===, = | "critical", "= 100", "== true" | { "op": "eq", "value": "critical" } | Scalar equality; finite numeric strings and numbers normalize before comparison via parseFinite |
neq | !=, !== | "!= closed", "!== 0" | { "op": "neq", "value": "closed" } | Logical negation of valuesEqual |
gt | > | "> 8" | { "op": "gt", "value": 8 } | Strictly greater than a finite numeric operand |
gte | >= | ">= 75" | { "op": "gte", "value": 75 } | Greater than or equal to a finite numeric operand |
lt | < | "< 2" | { "op": "lt", "value": 2 } | Strictly less than a finite numeric operand |
lte | <= | "<= -12" | { "op": "lte", "value": -12 } | Less than or equal to a finite numeric operand |
between | — | "[2..8]" | { "op": "between", "value": [2, 8] } | Closed numeric interval check min <= actual <= max |
in | — | "in [high, critical]" | { "op": "in", "value": ["high", "critical"] } | Matches if actual equals any element in the array |
not_in | not in | "not in [draft, cancelled]" | { "op": "not_in", "value": ["draft", "cancelled"] } | Matches if actual equals no element in the array |
contains | — | "contains COLD-" | { "op": "contains", "value": "COLD-" } | Case-insensitive substring check against String(actual) |
any | *, - | "*", "-", "any", "" | { "op": "any", "value": null } or null | Wildcard match; always evaluates to true |
When parsing shorthand strings, parseScalarValue coerces "true" / "false" to booleans, "null" to null, finite numeric literals matching /^-?\d+(?:\.\d+)?$/ to numbers, and strips balanced outer quotes ('...' or "..."). For string [a..b] ranges, parseStringConditionSpec normalizes bounds automatically via Math.min(a, b) and Math.max(a, b).
Production Decision Tables & logic.dmn Binding
The lattice-templates/dmn-tables/ repository directory ships three reference decision tables (cold_chain_approval_v1, cmms_priority_routing_v1, coldchain_settlement_policy_v1) alongside a 12-case sample-evaluations.json verification suite.
{
"tableKey": "cold_chain_approval_v1",
"name": "Cold-Chain & MKT Excursion Approval Matrix",
"hitPolicy": "FIRST",
"inputsJson": [
{ "name": "totalAmountM", "type": "number" },
{ "name": "maxTempC", "type": "number" }
],
"outputsJson": [
{ "name": "approvalTier", "type": "string" },
{ "name": "slaMinutes", "type": "number" }
],
"rulesJson": [
{
"when": { "maxTempC": { "op": "gt", "value": 8 } },
"then": { "approvalTier": "quality_hold_director", "slaMinutes": 15 }
},
{
"when": { "totalAmountM": "> 500" },
"then": { "approvalTier": "director_approval", "slaMinutes": 45 }
},
{
"when": { "totalAmountM": "*", "maxTempC": "*" },
"then": { "approvalTier": "manager_approval", "slaMinutes": 120 }
}
]
}Inside a LatticeFlow v2 DAG, logic.dmn merges { ...evalCtx.data, ...input, ...facts, organizationId } and invokes evaluateDecisionTable. Downstream nodes (control.if, control.approval, notify.send) read the decision outputs via {{dmn.approvalTier}} and {{dmnResult.outputs}}:
- For
FIRST,UNIQUE, andPRIORITY:context.dmnholds the matchedoutputsobject directly (such as{{dmn.approvalTier}}), andcontext.dmnResultholds{ tableKey, matched, hitPolicy, outputs }. - For
COLLECT:context.dmnholds{ results: [...] }containing every matched rule'sthenpayload inrulesJsonorder. - To inspect every matched rule index and priority score downstream, read the node output directly via
{{steps.dmn_gate.matchedRules}}.
If the target tableKey does not exist or has active: false in the organization, logic.dmn throws 404 DMN_TABLE_NOT_FOUND and routes execution along the node's error output edge when connected.
Evaluation & Authoring API (dxosDmn)
The dxosDmn resource exposes three actions protected by tenant FORCE ROW LEVEL SECURITY and scoped Personal Access Tokens (read, write, dmn).
/api/dxosDmn:listTables/api/dxosDmn:saveTable/api/dxosDmn:evaluateInline draft simulation (params.table) requires view or update ACL on latticeDecisionTables (or org-admin privileges) so analysts can test rule edits before publishing a new version.
curl -sS -X POST "https://app.latticedx.example.com/api/dxosDmn:evaluate" \
-H "Authorization: Bearer ldx_pat_your_token" \
-H "Content-Type: application/json" \
-d '{
"tableKey": "cold_chain_approval_v1",
"context": { "totalAmountM": 320, "maxTempC": 11.4 }
}'Security Boundaries & Error Codes
Every dxosDmn:saveTable call verifies organization admin status (isOrgAdmin) or explicit create/update collection permissions on latticeDecisionTables, and appends an immutable dmn.table_saved audit record under scope dxos:dmn to latticeCryptoLedger containing { tableKey, hitPolicy, version, ruleCount }.
| Error Code | HTTP | Trigger Condition |
|---|---|---|
DMN_OPERATOR_INVALID | 400 | Condition specifies an operator outside ALLOWED_OPERATORS |
DMN_RULE_INVALID | 400 | Numeric comparison receives non-finite value, invalid [min, max] range, or > 500 rules |
DMN_CONTEXT_INVALID | 400 | String context argument is not valid JSON |
DXOS_ACL_DENIED | 403 | Caller lacks org-admin role or latticeDecisionTables collection permission |
DMN_TABLE_NOT_FOUND | 404 | No active (active: true) table matches tableKey inside the caller organization |
DMN_UNIQUE_POLICY_VIOLATION | 409 | Table uses hitPolicy: "UNIQUE" and matched two or more rules |
