Validate cohort criteria with snapshots
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:
- Preview a sample of matching profiles.
- 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.
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.
1curl -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.
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.
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.
1curl -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:
profileCountis0: No profile in the store matches that identifier. Verify that you used the correct identifier and store; this isn't a criteria failure.profileCountis1andoverallMatchistrue: The profile matches the cohort's criteria.profileCountis1andoverallMatchisfalse: 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.
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.
- Learn more about Snapshots.
- See example criteria for common filtering patterns.
- Review Using Cohorts with Bulk Messaging and Email for details on sending campaigns to a cohort.