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

Validate cohort criteria with snapshots


Two ways to validate criteria

two-ways-to-validate-criteria page anchor

Before you rely on a cohort's filter criteria, confirm that the filter captures the population you expect. You can verify this in two ways:

  1. Preview a sample of matching profiles.
  2. Check whether a specific profile that you expect to match (or not match) actually does.

You can do either task with a snapshot. Because snapshots are immutable, point-in-time captures of matching profiles, you'll generate a new one each time you adjust the criteria as you validate.


Preview your criteria against a sample of profiles

preview-your-criteria-against-a-sample-of-profiles page anchor

While you iterate on the criteria, generate a snapshot directly from your inline criteria with a small profileLimit to get quick feedback. Project the fields that the criteria reference so that you can confirm the filtering logic against real data.

1
curl -X POST 'https://audiences.twilio.com/preview/CohortSnapshots' \
2
-H 'Content-Type: application/json' \
3
-d '{
4
"source": {
5
"storeType": "TWILIO",
6
"storeId": "mem_store_01h9d8r0vte3hz8tykdj329t7r",
7
"criteria": "profile.trait.Account.status == \"active\" && profile.trait.Account.country == \"US\""
8
},
9
"profileLimit": 10,
10
"variables": [
11
{ "expression": "profile.trait.Account.status", "displayName": "status" },
12
{ "expression": "profile.trait.Account.country", "displayName": "country" }
13
]
14
}' \
15
-u $TWILIO_API_KEY:$TWILIO_API_SECRET

After the operation completes, check the snapshot's profileCount to see the total number of matching profiles. Page through the sampled profiles to confirm that the projected values are as expected.

(information)

Info

Increase profileLimit for a larger sample, or omit the parameter to retrieve the full matching population. See Retrieving profiles for information about paging through large results.


Check whether a specific profile matches

check-whether-a-specific-profile-matches page anchor

Sometimes a broad sample is not enough—you might need to confirm that a specific profile is correctly included or excluded.

Target the profile by its identifier. In the same request, project three things:

  • The full criteria as a single Boolean (overallMatch).
  • Each individual sub-condition as its own Boolean.
  • The raw values behind them.
1
curl -X POST 'https://audiences.twilio.com/preview/CohortSnapshots' \
2
-H 'Content-Type: application/json' \
3
-d '{
4
"source": {
5
"storeType": "TWILIO",
6
"storeId": "mem_store_01h9d8r0vte3hz8tykdj329t7r",
7
"criteria": "\"jane@example.com\" in profile.address.email"
8
},
9
"variables": [
10
{ "expression": "profile.trait.Account.status == \"active\" && profile.trait.Account.country == \"US\"", "displayName": "overallMatch" },
11
{ "expression": "profile.trait.Account.status == \"active\"", "displayName": "statusActive" },
12
{ "expression": "profile.trait.Account.country == \"US\"", "displayName": "countryUs" },
13
{ "expression": "profile.trait.Account.status", "displayName": "statusValue" },
14
{ "expression": "profile.trait.Account.country", "displayName": "countryValue" }
15
]
16
}' \
17
-u $TWILIO_API_KEY:$TWILIO_API_SECRET

Interpret the result:

  • profileCount is 0: No profile in the store matches that identifier. Verify that you used the correct identifier and store; this isn't a criteria failure.
  • profileCount is 1 and overallMatch is true: The profile matches the cohort's criteria.
  • profileCount is 1 and overallMatch is false: The profile doesn't match.

In the example above, the per-condition Booleans (statusActive, countryUs) show how each clause evaluated, and the raw values (statusValue, countryValue) show the underlying data behind them. Together they explain why the profile did or did not match, regardless of whether overallMatch is true or false.

(information)

Info

Projecting each sub-condition as its own Boolean shows whether that piece matched, but it does not reveal how a mixed AND/OR expression combines them. For criteria such as A && B || C, which groups as (A && B) || C by operator precedence, you have two options:

  • Combine the leaf Booleans yourself in code based on that precedence.
  • Parse the criteria by the same precedence and project the grouped sub-expression—for example, (A && B)—so CEL evaluates that piece for you.