Switchflag
Evaluation

Operators

All 10 targeting rule operators available in the Switchflag evaluation engine.

The evaluation engine supports 10 operators for targeting rules. Each operator compares a context attribute against a rule value.

String operators

These operators convert both the context value and rule value to strings before comparing.

OperatorDescriptionExample
equalsExact string matchuserId equals "user-123"
notEqualsNot an exact matchemail notEquals "admin@acme.com"
containsSubstring matchemail contains "@acme.com"
startsWithStarts with prefixemail startsWith "admin"
endsWithEnds with suffixemail endsWith ".edu"

equals / notEquals

// Rule: email equals "jane@acme.com"
{ email: "jane@acme.com" }   // ✓ matches
{ email: "bob@acme.com" }    // ✗ no match

contains

// Rule: email contains "@acme.com"
{ email: "jane@acme.com" }      // ✓ matches
{ email: "admin@acme.com" }     // ✓ matches
{ email: "jane@example.com" }   // ✗ no match

startsWith / endsWith

// Rule: country startsWith "U"
{ country: "US" }   // ✓ matches
{ country: "UK" }   // ✓ matches
{ country: "CA" }   // ✗ no match

List operators

These check whether the context value is present in (or absent from) an array of allowed values.

OperatorDescriptionExample
inValue is in the listcountry in ["US", "CA", "GB"]
notInValue is not in the listcountry notIn ["CN", "RU"]
// Rule: country in ["US", "CA"]
{ country: "US" }   // ✓ matches
{ country: "CA" }   // ✓ matches
{ country: "GB" }   // ✗ no match

Numeric operators

These convert both values to numbers before comparing. Non-numeric values will produce NaN, which never matches.

OperatorDescriptionExample
greaterThanNumeric greater thanage greaterThan 18
lessThanNumeric less thanrequestCount lessThan 1000
// Rule: age greaterThan 18
{ age: 25 }    // ✓ matches
{ age: 18 }    // ✗ no match (not greater than)
{ age: 12 }    // ✗ no match

Percentage operator

The percent operator enables percentage-based rollouts. See Percentage Rollouts for details.

OperatorDescriptionExample
percentPercentage rolloutpercent at 50 (50% of users)

The percent operator requires userId in the context. It's deterministic — the same user always gets the same result for the same rule.

Missing attributes

If the context attribute referenced by a rule is undefined, the rule does not match. This applies to all operators except percent (which uses userId directly).

// Rule: country equals "US"
{ email: "jane@acme.com" }   // ✗ no match (country is undefined)