Blog Post
Collection Conditions: One Clause Instead of a Loop
Some of your context values are arrays — a cart’s line items, a list of scores, a set of flags. Asking a question about the whole array used to mean working around the engine: unroll the list into separate keys, add a rule per element, or precompute a total in an action first. AI Rule Engine now lets a single condition reason about a collection directly, with two new controls on a clause: Aggregate and Quantifier.
Aggregate: reduce, then compare
An aggregate collapses an array to a single number before the comparison runs. Set a clause’s aggregate to one of:
- Count — how many elements.
- Sum — the total.
- Average — the mean.
- Min / Max — the smallest or largest.
(None is the default and leaves the clause as-is.)
So “the cart total is under the limit” is one clause: aggregate Sum over the line-item amounts, operator Less than, value the limit. No precomputation, no helper key.
Because an aggregate produces a scalar, it only makes sense with a comparison operator — Equals, Not equal, Greater than / or equal, Less than / or equal, Between, or Not between. Pick an aggregate with the wrong kind of operator and the editor tells you: “Aggregates need a comparison operator (Equals, Greater/Less than, Between).”
Quantifier: test each element, then fold
A quantifier goes the other way. Instead of reducing the array first, it applies the operator to every element and folds the per-element results into one answer:
- Any element (the default) — true if the clause holds for at least one element.
- All elements — true only if it holds for every element.
- No element — true only if it holds for none.
So “any line item is over $500” is a clause with quantifier Any element and operator Greater than 500. “No item is out of stock” is No element with the appropriate test. The clause reads almost exactly like the sentence.
Before and after
Consider a cart-review RuleSet that needs two checks: flag any single expensive item, and confirm the whole cart stays under a limit.
Before, with per-element tests, you’d be duplicating rules or precomputing sums in actions and threading the results back into the context — logic that grows with the cart and is easy to get subtly wrong.
After, it’s two clauses on one rule:
- Any element of
lineItems.amountGreater than500 - Sum of
lineItems.amountLess thancartLimit
Both live right in the clause editor, and both show up in the decision table’s cell popover, so you can set them without leaving the grid.
The rules of the road
A few things keep this predictable:
- Aggregate and Quantifier are mutually exclusive. A clause is either reducing the array to a scalar or folding a per-element test — not both. Choosing one clears the other.
- They apply to array values. These controls are for context keys that hold a collection.
- Not available with AI-prompt operators. Aggregates and quantifiers work with the standard operator set, not with AI-prompt matching.
That’s the whole feature: two dropdowns on a clause that turn “loop over this array and check something” into a single line of logic you can read at a glance — and edit right in the decision table.
Visit RuleEngine.ai to try it.
The AI Rule Engine Team