---
name: audience-segments
description: Use when creating, editing or previewing notification.dev audience segments. Covers the segment expression grammar, the fields and operators available, previewing before saving, and the live-audience caveats of updating a segment.
---

# Audience segments

A segment is a saved audience rule. Campaigns can target it and journeys can
trigger on it. Read `notification-platform` first.

## Tools

| Tool                         | Permission       | Notes                                        |
| ---------------------------- | ---------------- | -------------------------------------------- |
| `list_segments`              | `segments:read`  | `projectId`, optional `cursor`               |
| `get_segment`                | `segments:read`  | `projectId`, `segmentId`                     |
| `preview_segment_expression` | `segments:read`  | `projectId`, `expression`; returns operation |
| `preview_segment`            | `segments:read`  | `projectId`, `segmentId`; returns operation  |
| `create_segment`             | `segments:write` | `projectId`, `input: { name, expression }`   |
| `update_segment`             | `segments:write` | `projectId`, `segmentId`, partial `input`    |

## Expression grammar

An expression is one of three node kinds. Groups nest to any depth.

```json
{ "kind": "and", "children": [ ...1 to 100 expressions ] }
{ "kind": "or",  "children": [ ...1 to 100 expressions ] }
```

```json
{
  "kind": "comparison",
  "field": { "source": "installation", "field": "platform" },
  "operator": "eq",
  "value": "ios"
}
```

```json
{
  "kind": "set",
  "field": { "source": "installation", "field": "locale" },
  "operator": "in",
  "values": ["en-US", "en-GB"]
}
```

Comparison operators: `eq`, `ne`, `gt`, `gte`, `lt`, `lte`. The `value` is a
string, number or boolean. Set operators: `in`, `not_in` with a `values` array.

## Fields

| `source`       | `field` or `key`                                             | Typical values                                                                                        |
| -------------- | ------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- |
| `tag`          | `key`: any tag name set by the app                           | string, number or boolean the app stored                                                              |
| `subscriber`   | `externalUserId`, `createdAt`                                | id string, ISO 8601 time                                                                              |
| `installation` | `platform`, `locale`, `timezone`, `appVersion`, `lastSeenAt` | `ios` / `android`, `en-US`, `Europe/Prague`, `2.4.0`, ISO time                                        |
| `subscription` | `provider`, `permission`, `optedIn`, `status`                | `apns` / `fcm` / `mock`, `authorized` / `denied` / `provisional` / `not_determined`, `true` / `false` |

Tags are written as `{ "source": "tag", "key": "plan" }`. Every other source uses
`field`.

## Example: active iOS users on a paid plan

```json
{
  "kind": "and",
  "children": [
    {
      "kind": "comparison",
      "field": { "source": "installation", "field": "platform" },
      "operator": "eq",
      "value": "ios"
    },
    {
      "kind": "comparison",
      "field": { "source": "tag", "key": "plan" },
      "operator": "eq",
      "value": "pro"
    },
    {
      "kind": "comparison",
      "field": { "source": "installation", "field": "lastSeenAt" },
      "operator": "gte",
      "value": "2026-09-01T00:00:00Z"
    }
  ]
}
```

## Workflow

1. Translate the user's description into an expression. Ask when a tag name or
   value is ambiguous instead of guessing.
2. Call `preview_segment_expression`, then poll `get_operation` until it
   completes. Report the count and a few sample subscribers back to the user.
3. Only then call `create_segment` with a clear, human name.
4. After creating, call `preview_segment` if the user wants the saved count.

## Updating a segment

`update_segment` rewrites a live audience. Active segment-triggered journeys and
future campaigns that reference it change immediately. Before updating:

- tell the user which journeys and campaigns reference the segment, using
  `list_journeys` and `list_campaigns`;
- offer to create a new segment instead when the change is a different audience;
- preview the new expression first.
