Skip to contentSkip to navigationSkip to topbar
Page tools
Useful for sharing or LLM
Accelerate development with AI

On this page
Looking for more inspiration?Visit the

Writing filter criteria


Overview

overview page anchor

Twilio Cohorts uses the Common Expression Language (CEL)(link takes you to an external page) to define filter criteria for audience targeting. Each criterion evaluates to true or false for every profile in your connected store. Profiles for which the criterion evaluates to true are added to the resulting cohort snapshot.

Filter criteria can reference two profile properties: traits and addresses.


Traits describe attributes attached to a profile, such as account tier, lifetime value, or sign-up date. Reference a trait by using profile.trait.{traitGroup}.{traitName}.

profile.trait.Account.status == "active"

Traits are typed as string, integer, float, boolean, timestamp, or duration. Array-typed traits aren't supported.

(information)

Info

{traitGroup} and {traitName} must exist in your connected store's schema. If either value isn't defined, the request is rejected as invalid.


Addresses represent contact channels attached to a profile, such as email addresses or phone numbers. Reference an address as profile.address.{channel}, where channel is email, phone, whatsapp, or chat.

Unlike traits, an address always returns a list of strings because a profile can have more than one address on the same channel (for example, two email addresses). You can't compare an address directly to a string. Instead, check for presence with has(), membership with in, or use list operations such as .exists().

"jane@example.com" in profile.address.email

Combine multiple conditions with logical operators:

profile.trait.Account.status == "active" && profile.trait.Account.country == "US"

For details on how operators are evaluated, see Operators and precedence.


Escape special characters in trait names

escape-special-characters-in-trait-names page anchor

Trait group and field names that contain periods, dashes, double underscores, or that start with a digit must be escaped before you reference them in filter criteria. See Escaping special characters for the complete list of escape sequences.


If a trait is absent on a profile, any comparison against it evaluates to false, which excludes the profile rather than raising an error. Use has() to check explicitly whether a trait is present. See Null handling for more information.


Both sides of a comparison must be the same data type. For example, comparing a string-typed trait to an integer literal triggers a validation error when you create or update a cohort. See Type matching for the full rules and available type-conversion functions.


Twilio Cohorts enforces the following limits on CEL expressions:

LimitValue
Maximum nesting depth6 levels of parenthesized nesting
Maximum criteria length10,000 characters
Maximum variable expression length500 characters
Maximum variables per snapshot50

Expressions that exceed these limits are rejected with an HTTP 422 Unprocessable Content error.


  • Learn about operators and precedence.
  • Browse the available functions.
  • Review example criteria for common filtering patterns.