Skip to content

Built-in rules and condition parameters

A condition attaches a rule name and parameters to an edge. The rule reads the session context, navigation history or evaluation time and returns whether that condition passes. Conditions on the same edge form an ordered AND: every condition must pass for the choice to proceed.

The default ConditionEvaluator registers the 15 names in the catalogue below. These are the names for canonical Condition objects, flat graph conditions records and FlowDSL’s when condition form. RuleFactory accepts a separate set of import aliases, documented later; those aliases are not automatically runtime rule names.

A flat graph condition has this shape. It belongs in the complete graph’s conditions array:

{
"edge_id": 10,
"rule": "context_value",
"params": {"key": "ready", "operator": "==", "value": true},
"version": "1.0.0"
}

The outer edge_id identifies the choice being checked. params belongs to the selected rule; version is optional and has a separate compatibility check. See the graph schema for record requirements.

At the rule interface, the operation is:

public function evaluate(
array $params,
Edge $edge,
SessionState $state,
?DateTimeImmutable $now = null,
): ConditionEvaluationResult;

This is a signature, not a standalone program. Edge is the candidate choice, SessionState is the state used for evaluation, and $now is the explicit instant passed by the evaluator. Temporal rules require it. ConditionEvaluationResult contains allowed: bool, nullable rule, reason, ekCode and an array context. A normal false result is different from an invalid rule that throws.

For built-ins, parameter validation rejects unknown keys, missing required values, wrong types and conflicting aliases. It normalizes a local copy for evaluation; it does not rewrite the graph’s declared parameters. Parameters are declarative arrays: scalars, null and nested arrays, without PHP objects or recursive references.

Rule Required parameters Optional parameters / defaults Meaning
context_value key: nonblank string; operator: supported string; value: required except for existence operators op aliases operator; no default comparison operator Compare the exact context key with the operand. No dotted-path traversal.
visited_node node_id: integer must_be_visited: boolean, default true Whether node history contains that ID anywhere. The starting root already counts as visited.
selected_edge edge_id: integer must_be_used: boolean, default true Whether edge history contains that previously accepted edge.

For visited_node, nodeId aliases node_id; mustBeVisited and expected alias must_be_visited. For selected_edge, edgeId aliases edge_id; mustBeUsed and expected alias must_be_used. Supplied aliases must agree by value and type.

History rules test presence, not counts, order or recency. A false flag requires absence. Evaluation happens before the candidate edge and its destination are added to history; a rule requiring the current edge to have been selected does not accept its first use. Context and history-based rules develops this distinction.

Every comparison except not_exists requires the key to be present. In particular, an absent key does not pass !=, not_in or not_contains.

Operator Operand contract Match
exists value unnecessary Key is present.
not_exists value unnecessary Key is absent.
==, != Any declarative value Strict PHP equality/inequality: value and type matter.
>, >=, <, <= Finite numeric value or numeric string Numeric comparison; the current value must also be finite and numeric. A nonnumeric current value blocks.
in, not_in A list, including an empty list Strict membership/nonmembership of the current value in value. An associative map is not a valid operand list.
contains, not_contains Declarative value If current value is an array, strict membership of the operand in that array. If current value is a string, case-sensitive substring matching with a string operand.

For other current types, contains is false and not_contains is true, provided the key exists. A string current value with a nonstring operand has the same result. An empty string operand is a substring of every string.

The session context imposes its own input contract before rule evaluation: null values are rejected; arrays require a core context policy with allowArrays: true. The deployed HTTP API accepts scalar context values only. A null rule operand is declarative data, but it does not make a missing context key compare equal to null.

The following cases use context key x:

Context Operator and operand Outcome
{} exists false
{} not_exists true
{} != true false
{"x": true} == true true
{"x": "true"} == true false
{} == null false
{"x": "12"} > 10 true
{"x": "twelve"} > 10 false
{"x": 1} in ["1"] false
{"x": ["red", "blue"]}, arrays enabled contains "blue" true
{"x": 7} not_contains "7" true
{"x": null} Any rule Rejected as invalid context before evaluating the rule

The complete context cases include the corresponding condition parameters, normal-failure reasons and the rejected-null diagnostic.

Temporal rules use the evaluator’s timezone, UTC by default, for calendar dates, hours and weekdays. The engine supplies an evaluation instant. Omitted bounds leave that side unrestricted, but a range/window still requires at least one actual constraint.

Rule Parameters Semantics and defaults
date_equals Required string value; aliases date, datetime Same local calendar day for a date-only value, or the same instant for an absolute target.
date_before Same parameter contract Inclusive: current day/instant is less than or equal to the target.
date_after Same parameter contract Inclusive: current day/instant is greater than or equal to the target.
absolute At least one of string after, before, equals Conjunction of the corresponding date-family comparisons. Bounds are inclusive.
date_range At least one of start_date, end_date Valid YYYY-MM-DD dates, inclusive. If both exist, start must not exceed end.
time_range At least one of start_time, end_time Valid HH:MM local clock labels. Inclusive whole minutes. Missing start/end means 00:00/23:59; start greater than end crosses midnight. Equal limits select one minute.
weekday weekdays: nonempty list of full English weekday names Case-insensitive monday through sunday. Uses the observed local weekday.
session_age At least one of integer min, max Nonnegative elapsed seconds since createdAt, inclusive. Aliases: min_session_age, max_session_age. Min must not exceed max; a future creation time blocks.
time_window At least one of start_date, end_date, start_time, end_time, weekdays, min_session_age, max_session_age All supplied constraints must pass, with the corresponding rules above. Optional nonblank window_id identifies the window in observations; it is not itself a constraint.
cron expression: valid cron string Predicate over the current local minute. Seconds do not distinguish matches within that minute. It does not schedule an operation.
time operator, source, target Source-based instant or elapsed-age comparison, described next.

Date-family string targets accept a valid calendar date, an absolute date-time or a canonical signed Unix-seconds string. Date-only value in the date family compares whole local days. An absolute date-time without an offset must resolve unambiguously in the evaluation zone; a repeated or nonexistent local time is invalid. Explicit offsets identify instants.

For time_window, optional fields cannot be supplied as null in place of a valid bound. weekdays uses full names in rule parameters; TimeDSL translates its shorter names. The TimeDSL reference supplies the grammar, fixed boundary results and daylight-saving cases.

source is exactly one of now, session_start, last_transition or context[KEY]. The context form reads the exact trimmed key. If its value cannot resolve to a date-time, the rule returns a blocked result with reason time_source_unresolved.

operator target Comparison
before Absolute date/time or Unix-seconds integer/string Source strictly earlier than target. Equality fails.
after Same Source strictly later than target. Equality fails.
between List of exactly two resolvable absolute targets Inclusive start and end. Ordering is checked with the actual evaluation timezone.
older_than Nonnegative integer seconds or canonical decimal string now - source > target; equality fails.
younger_than Same now - source < target; equality fails.

Duration strings use seconds, such as "60", not "1m", decimal fractions or redundant leading zeros. A date-only target in time resolves to local midnight, rather than a whole-day comparison. The low-level date-time helper also accepts a DateTimeImmutable; PHP objects are not declarative Condition.params.

This parameter fragment describes a strict deadline:

{
"operator": "before",
"source": "now",
"target": "2026-12-10T12:15:00+01:00"
}

At exactly that instant it fails. By comparison, time_range with end_time: "12:15" includes 12:15:59, and absolute with a before target includes equality. Choose the rule with the boundary your application requires.

The fifteenth built-in is custom_rule. It requires nonblank string handler; optional args and sandbox_context are arrays and default to []. The handler name must be registered in the evaluator’s customRules map, and actual execution needs a sandbox driver.

The wrapper passes the current context, candidate edge, current node, evaluation timestamp, arguments and sandbox context to that driver. A false handler result is a normal condition block; a missing driver or failed execution is an error. Custom rule evaluation gives the integration contract.

A separate PHP extension implements RuleInterface, exposes its name through getType(): string, and returns ConditionEvaluationResult. Registered external types own their parameter schema. Registration cannot replace a built-in or another registered name, and cannot occur during a runtime operation. See Plugin manifests and extension contracts.

RuleFactory::create(array $rule): Condition is used by the nested schema and TimeDSL compilation. It reads type, falling back to rule, and reads operands beside that name. For example:

{"type": "contextEquals", "field": "ready", "value": true}

This produces {"rule":"context_value","params":{"key":"ready","operator":"==","value":true}}. Supplying the operands only inside params is not this factory’s input contract.

Factory names Emitted rule / operator
contextValue, context_value context_value; explicit operator required
contextEquals, context_equals context_value, ==
contextNotEquals, context_not_equals context_value, !=
contextGreaterThan, context_greater_than context_value, >
contextGreaterOrEqual, context_greater_or_equal, contextGreaterThanOrEqual, context_greater_than_or_equal context_value, >=
contextLessThan, context_less_than context_value, <
contextLessOrEqual, context_less_or_equal, contextLessThanOrEqual, context_less_than_or_equal context_value, <=
contextIn/context_in, contextNotIn/context_not_in in, not_in respectively
contextContains/context_contains, contextNotContains/context_not_contains contains, not_contains respectively
contextExists/context_exists, contextNotExists/context_not_exists exists, not_exists respectively
visitedNode, visited_node visited_node
selectedEdge, selected_edge selected_edge
time, timeCondition, time_condition time
timeWindow, time_window time_window
dateRange, date_range; timeRange, time_range date_range; time_range
weekday, weekday_rule, weekday_rules weekday
sessionAge, session_age session_age
absolute, absolute_datetime, absolute_datetime_rule absolute
cron, cron_expression cron
custom, custom_rule custom_rule
authz, authz_policy, authzPolicy, authzPolicies authz_policy, which is not a default evaluator rule

Factory context operands accept key/field, operator/op and value. An operator supplied to a comparison-specific alias must match its implied operator. Existence aliases do not require value; the factory emits null for an omitted operand.

The remaining factory operand mappings are:

Family Factory operand aliases
History nodeId/node/node_id, or edgeId/edge/edge_id; the boolean flag aliases listed above.
time operator/op, source, target; between can construct an absent/null target from string from and to.
time_window start_date/startDate/from; end_date/endDate/to; start_time/startTime; end_time/endTime; weekdays; min_session_age/minSessionAge/min; max_session_age/maxSessionAge/max; window_id.
date_range, time_range Respective snake-case bounds or startDate/endDate, startTime/endTime.
session_age min/min_session_age/minSessionAge; corresponding max aliases.
absolute after/start_date/startDate; before/end_date/endDate; equals.
cron expression/cron.
custom_rule handler, optional args, sandbox_context.
Authorization normalization policy (fallback policy_id, policyId, id) or policies; optional roles, actions, resource, effect, conditions. An extension must implement their meaning.

weekday uses weekdays directly. The factory accepts optional version or legacy rule.version as a nonblank numeric semver string. Recognised aliases checked as a group must agree; the factory copies supported operands, while later rule validation establishes their semantic validity.

There are no factory cases for date_equals, date_before or date_after: use their canonical condition form, or the factory’s absolute family. Conversely, producing authz_policy does not install an authorization implementation. Its strict import and runtime use require the relevant extension. Do not copy factory aliases directly into canonical rule fields and assume the evaluator will translate them.

A payload query evaluates built-ins without running custom handlers or registered external rule implementations. Those rules normally remain pending; a known false built-in condition can still make the edge blocked. Invalid parameters, an unknown type or an unregistered custom handler are known errors and block the query rather than becoming pending. A missing sandbox driver is discovered on actual custom execution, not proved by a pending query.

Actual choice validates all declared condition contracts before executing rule implementations, then evaluates in order and stops on a false result. The application must still call choose(); displayed availability is not a reservation. See Condition evaluation and edge availability.

Situation Rule-level result / diagnostic
Valid condition passes allowed: true
Context comparison fails with key present context_value_failed, EK-RULE-003
Context comparison fails with key absent context_value_failed, EK-SESSION-003
History requirement fails visited_node_failed or selected_edge_failed, EK-RULE-003
Valid temporal restriction fails Rule-specific reason, EK-TIME-001
Unsupported evaluator type UnknownRuleTypeException, EK-RULE-001
Invalid built-in parameter InvalidRuleFormatException, EK-RULE-002, with rule, field, reason
Inconsistent temporal range TemporalValidationException, EK-VALIDATION-001
Unsupported factory rule name ImporterUnsupportedRuleException, EK-IMPORT-003
Missing/malformed factory operand or checked alias conflict ImporterMalformedSchemaException, EK-IMPORT-005

Strict graph loading can wrap a parameter error in EK-GRAPH-040 and then a loader structure exception; flexible loading records warnings for these parameter defects but does not make the invalid rule executable. A query exposes a safe condition_evaluation_error availability reason. Navigation rejection, SDK and HTTP mappings have their own surrounding contracts in Error codes and exceptions.