Active policy set
Loading…
All versions
| Version | # | Steps | Policies | Created | Status |
|---|
Operation registry
A closed registry — a policy set's steps can never use any op besides these
18 (app/modules/rules_engine/operations.py). No operation ever throws on a
"bad" input — a type mismatch turns that step into Invalid, which shows up in
that one policy's error description instead of failing the whole request. A step always
has the same shape: {"id", "op", "inputs": [...], "output": "data.…"}, where
inputs are references (context.…, action.…,
data.… pointing at an earlier step's output, etc.) or literals.
Comparison
| op | what it does | accepts | returns | notes |
|---|---|---|---|---|
| gte(a, b) | a ≥ b | 2 numbers | bool | — |
| lte(a, b) | a ≤ b | 2 numbers | bool | — |
| gt(a, b) | a > b (strict) | 2 numbers | bool | — |
| lt(a, b) | a < b (strict) | 2 numbers | bool | — |
| eq(a, b) | a == b | any 2 values | bool | bool and number are never "equal" (Python has True == 1 — deliberately blocked here) |
| ne(a, b) | a != b | any 2 values | bool | mirrors eq, same guard, result inverted |
| in(value, options) | value ∈ options | value + array | bool | second argument must be an array, otherwise error |
Logical
| op | what it does | accepts | returns | notes |
|---|---|---|---|---|
| not(a) | ¬a | 1 bool | bool | — |
| and(a, b) | a ∧ b | exactly 2 bool | bool | for 3+ conditions — see all |
| or(a, b) | a ∨ b | exactly 2 bool | bool | for 3+ conditions — see any |
| all(a, b, …) | a₁ ∧ a₂ ∧ … ∧ aₙ | ≥2 bool (any count) | bool | N-ary AND — combines 3+ conditions in one step |
| any(a, b, …) | a₁ ∨ a₂ ∨ … ∨ aₙ | ≥2 bool (any count) | bool | N-ary OR |
Arithmetic & dates
| op | what it does | accepts | returns | notes |
|---|---|---|---|---|
| subtract(a, b) | a − b | 2 numbers | number | — |
| add(a, b) | a + b | 2 numbers | number | — |
| divide(a, b) | a ÷ b | 2 numbers, b ≠ 0 | number | division by zero → error (the step becomes Invalid) |
| date_diff_days(a, b) | (date_a − date_b).days | 2 ISO 8601 date strings (e.g. "2026-09-01") | integer number of days | invalid date format → error |
In every arithmetic/comparison operation, bool is deliberately NOT accepted as a number — even though True/False are technically int (0/1) in Python, that's blocked here so a boolean value can't silently slip in in place of a numeric fact.
Array selection (FIFO/FEFO)
| op | what it does | accepts | returns | notes |
|---|---|---|---|---|
| min_by(array, compare_fields, select_field) | picks the array element with the minimum key (ties are broken by the next field in the list) | array of objects; compare_fields — a non-empty list of field names to compare; select_field — the name of the result field |
the select_field value of the chosen element |
field values must be an ISO date or a number (don't mix); an empty array → MISSING, not an error; a full tie across every field → deterministically the first one in array order |
| max_by(array, compare_fields, select_field) | same, but maximum | same | same | mirrors min_by |
Example for FEFO (First-Expired-First-Out): min_by(context.batches, ["expiry_date"], "batch_id") — the id of the batch with the nearest expiry date.
Demo scenarios
The same canonical scenarios as scripts/live_demo.py,
scripts/_client.py, and scripts/data/synthetic_batch_records.json
(baseline doc §12) — ready-made data for a quick check without hand-typing JSON.
"Load rules" registers the needed policy set (POST /policy-sets) and makes it
the current active one. "Fill …" only populates the relevant tab's fields — you run the
actual check there yourself, with the "Run" button.
Round 1 — minimal policy set (1 step, 1 policy)
Not loaded in this session yet.
Round 2 — combined policy set (9 steps, 5 policies)
Not loaded in this session yet.
Batch data (19 records)
Uses the same policy set as Round 2 above — click "Load rules" there first if you need it.
19 records: REPLENISH/TRANSFER → ALLOW (numeric variations), TRANSFER → HOLD (the donor is
missing coverage_floor), ACCEPT_SHORTFALL → ESCALATE (all three reasons:
no_compatible_action / requires_human_approval / verify),
and one record missing the action.reason_code required for ACCEPT_SHORTFALL —
demonstrating that one invalid record doesn't sink the whole batch (it comes back as
status: "error", the rest process normally).
API key for requests
Request
To pin a specific, already-created version instead of the current active one — paste its version from the list in the Rules tab.
Result
No result yet.
API key for requests
Records (JSON array)
Applies only to records in the array that don't specify their own policy_version —
a record with its own value takes priority over this. To pin a version for just one record
instead of the whole batch — write "policy_version": "…" directly in that
record's JSON.
Results
| # | Status | Verdict | Description | decision_id |
|---|
Decision history
| Evaluated | Verdict | action_type | reason_codes | policy_set_version | decision_id |
|---|
Replay a decision
Re-runs the policy set the decision was originally made under and compares the verdict — a reproducibility check.
Create key
Keys
| Name | Prefix | Created | Last used | Status |
|---|
Users
| Name | Status | ID |
|---|