Decision tables
Evaluate business rules written as decision tables, as in DMN 1.4: one column per input, one per output, one row per rule, with the hit policies UNIQUE, ANY, FIRST, PRIORITY, COLLECT (with SUM, MIN, MAX or COUNT), RULE ORDER and OUTPUT ORDER. rules eval gives the result of one case, rules eval_rows adds the outputs to every row of a table, and rules explain shows which entry of each rule matched or failed and why. Typical uses: a discount or pricing grid, an eligibility or approval check, the routing of a request to the right team.
rules eval <table> <input>
Description
The result of a decision table for one case: the outputs as a JSON object for UNIQUE, ANY, FIRST and PRIORITY, a JSON array of output objects for COLLECT, RULE ORDER and OUTPUT ORDER, and {output: value} for an aggregation
The result of a decision table for one case: the outputs as a JSON object for UNIQUE, ANY, FIRST and PRIORITY, a JSON array of output objects for COLLECT, RULE ORDER and OUTPUT ORDER, and {output: value} for an aggregation
Parameters
table: The decision table, as JSON {"hit_policy", "inputs", "outputs", "rules"} (4 MB at most), for example the result of rules from_csv - String - required
input: The values of one case, as a JSON object {input name: value} - String - required
table: The decision table, as JSON {"hit_policy", "inputs", "outputs", "rules"} (4 MB at most), for example the result of rules from_csv - String - required
input: The values of one case, as a JSON object {input name: value} - String - required
admin
rules eval "{\"name\": \"discount\", \"hit_policy\": \"UNIQUE\", \"inputs\": [{\"name\": \"customer\", \"type\": \"string\", \"values\": [\"Business\", \"Private\"]}, {\"name\": \"orderSize\", \"type\": \"number\"}], \"outputs\": [{\"name\": \"discount\", \"type\": \"number\", \"default\": 0}], \"rules\": [{\"when\": [\"\\"Business\\"\", \"<10\"], \"then\": 0.1, \"description\": \"small business order\"}, {\"when\": [\"\\"Business\\"\", \">=10\"], \"then\": 0.15}, {\"when\": [\"\\"Private\\"\", \"-\"], \"then\": 0.05}]}" "{\"customer\": \"Business\", \"orderSize\": 12}"
mentdb
{"discount": 0.15}
No rule matches: the default
admin
rules eval "{\"name\": \"discount\", \"hit_policy\": \"UNIQUE\", \"inputs\": [{\"name\": \"customer\", \"type\": \"string\", \"values\": [\"Business\", \"Private\"]}, {\"name\": \"orderSize\", \"type\": \"number\"}], \"outputs\": [{\"name\": \"discount\", \"type\": \"number\", \"default\": 0}], \"rules\": [{\"when\": [\"\\"Business\\"\", \"<10\"], \"then\": 0.1, \"description\": \"small business order\"}, {\"when\": [\"\\"Business\\"\", \">=10\"], \"then\": 0.15}, {\"when\": [\"\\"Private\\"\", \"-\"], \"then\": 0.05}]}" "{\"customer\": \"Business\"}"
mentdb
{"discount": 0}
FIRST: the first matching rule, two outputs
admin
rules eval "{\"hit_policy\": \"FIRST\", \"inputs\": [{\"name\": \"country\", \"type\": \"string\"}, {\"name\": \"weight\", \"type\": \"number\"}, {\"name\": \"express\", \"type\": \"boolean\"}], \"outputs\": [{\"name\": \"carrier\", \"type\": \"string\"}, {\"name\": \"price\", \"type\": \"number\"}], \"rules\": [[\"\\"FR\\"\", \"<=2\", \"false\", \"La Poste\", 4.9], [\"\\"FR\\", \\"BE\\", \\"LU\\"\", \"(2..30]\", \"-\", \"Colissimo\", 12.5], [\"not(\\"FR\\")\", \"<=30\", \"true\", \"DHL Express\", 39], [\"-\", \"-\", \"-\", \"Freight\", 120]]}" "{\"country\": \"BE\", \"weight\": 4.2, \"express\": false}"
mentdb
{"carrier": "Colissimo", "price": 12.5}
PRIORITY: DECLINE comes before REFER and ACCEPT
admin
rules eval "{\"hit_policy\": \"PRIORITY\", \"inputs\": [{\"name\": \"age\", \"type\": \"number\", \"integer\": true, \"values\": \"[18..120]\"}, {\"name\": \"score\", \"type\": \"number\"}, {\"name\": \"since\", \"type\": \"date\"}], \"outputs\": [{\"name\": \"decision\", \"type\": \"string\", \"values\": [\"DECLINE\", \"REFER\", \"ACCEPT\"]}], \"rules\": [[\"-\", \">=700\", \"-\", \"ACCEPT\"], [\"-\", \"[600..700)\", \"-\", \"REFER\"], [\"-\", \"<600\", \"-\", \"DECLINE\"], [\"<21\", \"-\", \"-\", \"REFER\"], [\"-\", \"-\", \">date(\\"2026-01-01\\")\", \"REFER\"]]}" "{\"age\": 30, \"score\": 580, \"since\": \"2026-03-01\"}"
mentdb
{"decision": "DECLINE"}
COLLECT SUM: loyalty points
admin
rules eval "{\"hit_policy\": \"COLLECT\", \"aggregation\": \"SUM\", \"inputs\": [\"basket:number\", \"member:boolean\"], \"outputs\": [\"points:number\"], \"rules\": [[\">=50\", \"-\", 5], [\">=100\", \"-\", 10], [\"-\", \"true\", 2]]}" "{\"basket\": 120, \"member\": true}"
mentdb
{"points": 17}
RULE ORDER: every approver
admin
rules eval "{\"hit_policy\": \"RULE ORDER\", \"inputs\": [\"amount:number\", \"category:string\"], \"outputs\": [\"approver:string\"], \"rules\": [[\">1000\", \"-\", \"manager\"], [\">10000\", \"-\", \"director\"], [\"-\", \"\\"IT\\"\", \"it_lead\"]]}" "{\"amount\": 25000, \"category\": \"IT\"}"
mentdb
[{"approver": "manager"}, {"approver": "director"}, {"approver": "it_lead"}]
UNIQUE: two rules match, an error
admin
rules eval "{\"inputs\": [\"age:number\"], \"outputs\": [\"band:string\"], \"rules\": [[\"<=18\", \"A\"], [\">=18\", \"B\"]]}" "{\"age\": 18}"
mentdb
ERROR: Sorry, an error appears (the hit policy UNIQUE is violated: rules 1 and 2 both match this input).
rules eval <table> <input> <json_params>
Description
The result with parameters: value (false: true gives the value alone for a table with one output: a text without quotes, a number, an empty text for null, a JSON array for several rules), trace (false: true gives {result, matched_rules, used_default})
The result with parameters: value (false: true gives the value alone for a table with one output: a text without quotes, a number, an empty text for null, a JSON array for several rules), trace (false: true gives {result, matched_rules, used_default})
Parameters
table: The decision table, as JSON {"hit_policy", "inputs", "outputs", "rules"} (4 MB at most), for example the result of rules from_csv - String - required
input: The values of one case, as a JSON object {input name: value} - String - required
json_params: The parameters, as a JSON object - String - required
table: The decision table, as JSON {"hit_policy", "inputs", "outputs", "rules"} (4 MB at most), for example the result of rules from_csv - String - required
input: The values of one case, as a JSON object {input name: value} - String - required
json_params: The parameters, as a JSON object - String - required
admin
rules eval "{\"name\": \"discount\", \"hit_policy\": \"UNIQUE\", \"inputs\": [{\"name\": \"customer\", \"type\": \"string\", \"values\": [\"Business\", \"Private\"]}, {\"name\": \"orderSize\", \"type\": \"number\"}], \"outputs\": [{\"name\": \"discount\", \"type\": \"number\", \"default\": 0}], \"rules\": [{\"when\": [\"\\"Business\\"\", \"<10\"], \"then\": 0.1, \"description\": \"small business order\"}, {\"when\": [\"\\"Business\\"\", \">=10\"], \"then\": 0.15}, {\"when\": [\"\\"Private\\"\", \"-\"], \"then\": 0.05}]}" "{\"customer\": \"Business\", \"orderSize\": 3}" "{\"value\": true}"
mentdb
0.1
Which rule gave the result
admin
rules eval "{\"hit_policy\": \"FIRST\", \"inputs\": [{\"name\": \"country\", \"type\": \"string\"}, {\"name\": \"weight\", \"type\": \"number\"}, {\"name\": \"express\", \"type\": \"boolean\"}], \"outputs\": [{\"name\": \"carrier\", \"type\": \"string\"}, {\"name\": \"price\", \"type\": \"number\"}], \"rules\": [[\"\\"FR\\"\", \"<=2\", \"false\", \"La Poste\", 4.9], [\"\\"FR\\", \\"BE\\", \\"LU\\"\", \"(2..30]\", \"-\", \"Colissimo\", 12.5], [\"not(\\"FR\\")\", \"<=30\", \"true\", \"DHL Express\", 39], [\"-\", \"-\", \"-\", \"Freight\", 120]]}" "{\"country\": \"US\", \"weight\": 1, \"express\": true}" "{\"trace\": true}"
mentdb
{"result": {"carrier": "DHL Express", "price": 39}, "matched_rules": ["3"], "used_default": false}
Used in use cases (1 recipe)
Financial analyst › Pre-approve a loan with a priority table and keep the reasons in the file
Financial analyst › Pre-approve a loan with a priority table and keep the reasons in the file
rules eval_rows <table> <rows>
Description
The rows of a table with the outputs added as columns (100000 rows by default): for COLLECT, RULE ORDER and OUTPUT ORDER each output column is a list. The first case that fails stops everything, with the number of its row. An output replaces a column of the same name
The rows of a table with the outputs added as columns (100000 rows by default): for COLLECT, RULE ORDER and OUTPUT ORDER each output column is a list. The first case that fails stops everything, with the number of its row. An output replaces a column of the same name
Parameters
table: The decision table, as JSON {"hit_policy", "inputs", "outputs", "rules"} (4 MB at most), for example the result of rules from_csv - String - required
rows: The rows, as a JSON array of objects (the result of sql to json, csv read...) - String - required
table: The decision table, as JSON {"hit_policy", "inputs", "outputs", "rules"} (4 MB at most), for example the result of rules from_csv - String - required
rows: The rows, as a JSON array of objects (the result of sql to json, csv read...) - String - required
admin
rules eval_rows "{\"name\": \"discount\", \"hit_policy\": \"UNIQUE\", \"inputs\": [{\"name\": \"customer\", \"type\": \"string\", \"values\": [\"Business\", \"Private\"]}, {\"name\": \"orderSize\", \"type\": \"number\"}], \"outputs\": [{\"name\": \"discount\", \"type\": \"number\", \"default\": 0}], \"rules\": [{\"when\": [\"\\"Business\\"\", \"<10\"], \"then\": 0.1, \"description\": \"small business order\"}, {\"when\": [\"\\"Business\\"\", \">=10\"], \"then\": 0.15}, {\"when\": [\"\\"Private\\"\", \"-\"], \"then\": 0.05}]}" "[{\"order\": \"A-1\", \"customer\": \"Business\", \"orderSize\": 4}, {\"order\": \"A-2\", \"customer\": \"Private\", \"orderSize\": 40}]"
mentdb
[{"order": "A-1", "customer": "Business", "orderSize": 4, "discount": 0.1}, {"order": "A-2", "customer": "Private", "orderSize": 40, "discount": 0.05}]
rules eval_rows <table> <rows> <json_params>
Description
The rows with parameters: matched_column (a column to add with the ids of the matched rules), on_error (stop, or column: the row gets null outputs and the message in error_column), error_column (rules_error), max_rows (100000, 1000000 at most). JSON rows of 64 MB at most, and rows x tests of the table of 1 billion at most (each entry is one test, each value of a list one more: about 3 seconds of work); split bigger jobs
The rows with parameters: matched_column (a column to add with the ids of the matched rules), on_error (stop, or column: the row gets null outputs and the message in error_column), error_column (rules_error), max_rows (100000, 1000000 at most). JSON rows of 64 MB at most, and rows x tests of the table of 1 billion at most (each entry is one test, each value of a list one more: about 3 seconds of work); split bigger jobs
Parameters
table: The decision table, as JSON {"hit_policy", "inputs", "outputs", "rules"} (4 MB at most), for example the result of rules from_csv - String - required
rows: The rows, as a JSON array of objects - String - required
json_params: The parameters, as a JSON object - String - required
table: The decision table, as JSON {"hit_policy", "inputs", "outputs", "rules"} (4 MB at most), for example the result of rules from_csv - String - required
rows: The rows, as a JSON array of objects - String - required
json_params: The parameters, as a JSON object - String - required
admin
rules eval_rows "{\"name\": \"discount\", \"hit_policy\": \"UNIQUE\", \"inputs\": [{\"name\": \"customer\", \"type\": \"string\", \"values\": [\"Business\", \"Private\"]}, {\"name\": \"orderSize\", \"type\": \"number\"}], \"outputs\": [{\"name\": \"discount\", \"type\": \"number\", \"default\": 0}], \"rules\": [{\"when\": [\"\\"Business\\"\", \"<10\"], \"then\": 0.1, \"description\": \"small business order\"}, {\"when\": [\"\\"Business\\"\", \">=10\"], \"then\": 0.15}, {\"when\": [\"\\"Private\\"\", \"-\"], \"then\": 0.05}]}" "[{\"customer\": \"Business\", \"orderSize\": 4}, {\"customer\": \"Partner\", \"orderSize\": 4}]" "{\"on_error\": \"column\", \"matched_column\": \"rule\"}"
mentdb
[{"customer": "Business", "orderSize": 4, "discount": 0.1, "rule": ["1"], "rules_error": null}, {"customer": "Partner", "orderSize": 4, "discount": null, "rule": [], "rules_error": "the value \"Partner\" of input 'customer' is not allowed (\"Business\", \"Private\")"}]
rules explain <table> <input>
Description
Why a case gives its result: JSON {hit_policy, input (the converted values), result, matched_rules, used_default, rules: [{rule, matched, entries: [{input, test, matched, why}], outputs}]}. A violation of UNIQUE or ANY is given in error, not thrown. For a table of more than 100000 rules x inputs, use matched_only
Why a case gives its result: JSON {hit_policy, input (the converted values), result, matched_rules, used_default, rules: [{rule, matched, entries: [{input, test, matched, why}], outputs}]}. A violation of UNIQUE or ANY is given in error, not thrown. For a table of more than 100000 rules x inputs, use matched_only
Parameters
table: The decision table, as JSON {"hit_policy", "inputs", "outputs", "rules"} (4 MB at most), for example the result of rules from_csv - String - required
input: The values of one case, as a JSON object {input name: value} - String - required
table: The decision table, as JSON {"hit_policy", "inputs", "outputs", "rules"} (4 MB at most), for example the result of rules from_csv - String - required
input: The values of one case, as a JSON object {input name: value} - String - required
admin
rules explain "{\"name\": \"discount\", \"hit_policy\": \"UNIQUE\", \"inputs\": [{\"name\": \"customer\", \"type\": \"string\", \"values\": [\"Business\", \"Private\"]}, {\"name\": \"orderSize\", \"type\": \"number\"}], \"outputs\": [{\"name\": \"discount\", \"type\": \"number\", \"default\": 0}], \"rules\": [{\"when\": [\"\\"Business\\"\", \"<10\"], \"then\": 0.1, \"description\": \"small business order\"}, {\"when\": [\"\\"Business\\"\", \">=10\"], \"then\": 0.15}, {\"when\": [\"\\"Private\\"\", \"-\"], \"then\": 0.05}]}" "{\"customer\": \"Business\", \"orderSize\": 12}"
mentdb
{"hit_policy": "UNIQUE", "input": {"customer": "Business", "orderSize": 12}, "result": {"discount": 0.15}, "matched_rules": ["2"], "used_default": false, "rules": [{"rule": "1", "description": "small business order", "matched": false, "entries": [{"input": "customer", "test": "\"Business\"", "matched": true, "why": "\"Business\" satisfies \"Business\""}, {"input": "orderSize", "test": "<10", "matched": false, "why": "12 does not satisfy <10"}], "outputs": {"discount": 0.1}}, {"rule": "2", "matched": true, "entries": [{"input": "customer", "test": "\"Business\"", "matched": true, "why": "\"Business\" satisfies \"Business\""}, {"input": "orderSize", "test": ">=10", "matched": true, "why": "12 satisfies >=10"}], "outputs": {"discount": 0.15}}, {"rule": "3", "matched": false, "entries": [{"input": "customer", "test": "\"Private\"", "matched": false, "why": "\"Business\" does not satisfy \"Private\""}, {"input": "orderSize", "test": "-", "matched": true, "why": "- accepts any value"}], "outputs": {"discount": 0.05}}]}
rules explain <table> <input> <json_params>
Description
The explanation with parameters: matched_only (false: true lists the matched rules only)
The explanation with parameters: matched_only (false: true lists the matched rules only)
Parameters
table: The decision table, as JSON {"hit_policy", "inputs", "outputs", "rules"} (4 MB at most), for example the result of rules from_csv - String - required
input: The values of one case, as a JSON object {input name: value} - String - required
json_params: The parameters, as a JSON object - String - required
table: The decision table, as JSON {"hit_policy", "inputs", "outputs", "rules"} (4 MB at most), for example the result of rules from_csv - String - required
input: The values of one case, as a JSON object {input name: value} - String - required
json_params: The parameters, as a JSON object - String - required
admin
rules explain "{\"hit_policy\": \"RULE ORDER\", \"inputs\": [\"amount:number\", \"category:string\"], \"outputs\": [\"approver:string\"], \"rules\": [[\">1000\", \"-\", \"manager\"], [\">10000\", \"-\", \"director\"], [\"-\", \"\\"IT\\"\", \"it_lead\"]]}" "{\"amount\": 25000, \"category\": \"HR\"}" "{\"matched_only\": true}"
mentdb
{"hit_policy": "RULE ORDER", "input": {"amount": 25000, "category": "HR"}, "result": [{"approver": "manager"}, {"approver": "director"}], "matched_rules": ["1", "2"], "used_default": false, "rules": [{"rule": "1", "matched": true, "entries": [{"input": "amount", "test": ">1000", "matched": true, "why": "25000 satisfies >1000"}, {"input": "category", "test": "-", "matched": true, "why": "- accepts any value"}], "outputs": {"approver": "manager"}}, {"rule": "2", "matched": true, "entries": [{"input": "amount", "test": ">10000", "matched": true, "why": "25000 satisfies >10000"}, {"input": "category", "test": "-", "matched": true, "why": "- accepts any value"}], "outputs": {"approver": "director"}}]}
Used in use cases (1 recipe)
Financial analyst › Pre-approve a loan with a priority table and keep the reasons in the file
Financial analyst › Pre-approve a loan with a priority table and keep the reasons in the file
