Skip to main content

Rules

A feature flag's rules determine the variation to serve if all of the conditions of a rule are met. The rules are evaluated in the order in which they are listed and are unique across environments (creating a rule in one environment does not transfer to another one).

Use the 'Development' or 'Production' buttons to switch between environments.

Adding a rule​

Adding a rule to a feature flag can be done from within the Rules tab of the feature flag details page. Use the 'Add rule' dropdown to select the kind of rule to add: a Custom Rule or a Segment Rule.

New rules are added to the top of the list, so they are evaluated first.

Custom rule

A Custom Rule allows you to define any combination of context-attribute-operator-values you desire.

A rule key must be unique and follow a lowercase, kebab-case convention (for example, my-feature-flag-rule). The first condition of a rule is prefixed with IF and each additional condition with AND, meaning all conditions must be met for the rule to serve its variation.

Segment rule

A Segment Rule allows you to define any combination of context-attribute-operator-values you desire along with segment-specific conditions.

The available segments are managed within the segment's details page.

A segment condition pairs an operator of is in or is not in with the segment you select. Only segments belonging to the flag's application are available for selection.

Context​

The context of a rule aligns with the context set when setting the provider in your application using OpenFeature.setProvider or when updating the context via OpenFeature.setContext. You can either select a predefined context or enter your own.

More about the evaluation context and how OpenFeature defines it can be found here.

danger

Personally Identifiable Information (PII) should not be used in Context. Using PII can pose a security risk, as it could potentially be exposed or misused during feature flag evaluation. This is because the evaluation context, including the PII, might be logged or transmitted for debugging and analysis purposes.

Attribute​

The attribute is any property which exists within the context. For example, you may have user.country in your context where country is the attribute. You can either select a predefined attribute or enter your own.

info

If you need to access deeply nested attributes, you can use dot notation for your attribute.

Example: You need to access user.country.address.line1 from your context. In order to access line1 as your evaluation, set your attribute to country.address.line1.

Operator​

The operator is the logical comparator used to evaluate the feature flag. It takes your context attribute and compares it against the values. The following table shows all available operators and their common use cases:

OperatorUse CaseExample
containsCheck if a string value contains a substring. Also use this for boolean values (e.g., true, false).Check if user email contains @company.com or if some context is true
does not containCheck if a string value does not contain a substringExclude users with emails containing @competitor.com
starts withCheck if a string value begins with specific charactersShow specific features for specific routes where a route might start with /settings/notifications
does not start withCheck if a string value does not begin with specific charactersExclude users with usernames that don't start with admin
ends withCheck if a string value ends with specific charactersTarget users with emails ending in @example.com
does not end withCheck if a string value does not end with specific charactersExclude beta testers with emails not ending in @beta.com
greater thanCompare numeric values for values above a thresholdTarget users with loyalty points greater than 1000
greater than or equalCompare numeric values for values at or above a thresholdTarget users with loyalty points at 1000 or more
less thanCompare numeric values for values below a thresholdTarget users with less than 5 login attempts
less than or equalCompare numeric values for values at or below a thresholdTarget users with account age 30 days or less
equalsMatch valueTarget users in specific country (US)
does not equalExclude specific valueExclude users in specific country (US)
is one ofMatch a context attribute against any value in a listTarget users whose user.language is english or spanish
is not one ofMatch a context attribute only when it matches none of the values in a listExclude users whose user.language is english or spanish
matches minor versionCompare semantic versions at minor levelTarget applications running version 1.2.x
matches major versionCompare semantic versions at major levelTarget applications running version 2.x.x
Boolean Values

To use boolean values (true or false) in your rules, you must use the contains operator. We understand this isn't intuitive. We are working on improving the UX around rule creation when it comes to handling different data types.

Example: To check if user (context) isNew (attribute) is set to true, set your operator to "contains" and value to true.

This is a complete list of the available operators.

Values​

Values align with the value of your context's attribute.

Multiple values​

To compare a context attribute against a list of values, select is one of or is not one of. These operators display a list input where you enter one value per line or paste a list from a spreadsheet or text file. Multiple values are only supported with these two operators. All values must match the selected type.

For example, consider this evaluation context:

{
"user": {
"language": "english"
}
}

Here, user.language is a single string, not an array. Configure the condition as follows:

FieldValue
Contextuser
Attributelanguage
Operatoris one of
TypeString

Enter these strings in the Value field, one per line:

english
spanish
french

The condition matches because english is one of the strings in the list. With is not one of, the same condition would not match; a value outside the list, such as german, would match instead.

The rule serves its configured variation when this condition and all other conditions in the rule are met, provided no earlier rule matches.

Editing a rule​

You can edit any existing rule to modify its conditions, variations, or rollout settings. The rule key is the only part of a rule that cannot be changed.

Canceling edits​

If you need to discard changes made while editing a rule, click the 'Cancel edit' button. This will revert any changes made to the rule and return it to its previous state.

Default rule​

Every feature flag requires a default rule. This rule will serve the default variation set during the creation of the feature flag and can be updated to any other one of the feature flag's variations or can be set to a weighted rollout.

The default rule is always the last entry in the rules list.

Rule sorting​

You can sort rules using drag and drop via the sidebar on the right side of the screen. Simply drag a rule to change its order of evaluation. If there is only one rule available, drag and drop sorting is disabled.

info

The Default Rule acts as a catch-all and cannot be reordered.

Rollouts​

Rollouts allow you to define the variation to serve when all conditions of a rule are met. It also lets you define a weighted rollout.

A rule can either serve a single variation or serve a weighted rollout, where you assign a weight to each variation. The rollout is distributed using the context and attribute you specify so that the same user consistently receives the same variation.