# Segment User

**Action ID:** `segment_user`

## Description

Segment user.

## Input Parameters

| Name  | Type   | Required | Default | Description                                                           |
| ----- | ------ | :------: | ------- | --------------------------------------------------------------------- |
| users | string |     ✓    | -       | List of users in JSON format. Should be a JSON array of user objects. |

<details>

<summary>View JSON Schema</summary>

```json
{
  "description": "Segment user",
  "properties": {
    "users": {
      "description": "List of users in JSON format.",
      "title": "List of Users",
      "type": "string"
    }
  },
  "required": [
    "users"
  ],
  "title": "SegmentUserNodeInput",
  "type": "object"
}
```

</details>

## Output Parameters

| Name     | Type  | Description                                 |
| -------- | ----- | ------------------------------------------- |
| segments | array | User segments with categorized user groups. |

<details>

<summary>View JSON Schema</summary>

```json
{
  "description": "Segment user output",
  "properties": {
    "segments": {
      "description": "User segments.",
      "items": {
        "additionalProperties": true,
        "type": "object"
      },
      "title": "User Segments",
      "type": "array"
    }
  },
  "required": [
    "segments"
  ],
  "title": "SegmentUserNodeOutput",
  "type": "object"
}
```

</details>

## How It Works

This node analyzes a list of users and intelligently segments them into distinct groups based on their attributes, behaviors, or characteristics. It processes the user data, applies segmentation logic or criteria, and returns organized segments with users grouped by common traits. The segmentation helps identify patterns and categorize users for targeted actions, personalized experiences, or analytics.

## Usage Examples

### Example 1: Segment by Activity Level

**Input:**

```
users: '[
  {"id": 1, "name": "Alice", "logins": 45, "purchases": 12},
  {"id": 2, "name": "Bob", "logins": 3, "purchases": 0},
  {"id": 3, "name": "Carol", "logins": 28, "purchases": 5},
  {"id": 4, "name": "David", "logins": 1, "purchases": 0}
]'
```

**Output:**

```
segments: [
  {
    "segment_name": "Power Users",
    "count": 1,
    "users": [{"id": 1, "name": "Alice", "logins": 45, "purchases": 12}]
  },
  {
    "segment_name": "Active Users",
    "count": 1,
    "users": [{"id": 3, "name": "Carol", "logins": 28, "purchases": 5}]
  },
  {
    "segment_name": "Inactive Users",
    "count": 2,
    "users": [
      {"id": 2, "name": "Bob", "logins": 3, "purchases": 0},
      {"id": 4, "name": "David", "logins": 1, "purchases": 0}
    ]
  }
]
```

### Example 2: Segment by Purchase Behavior

**Input:**

```
users: '[
  {"id": 101, "email": "user1@example.com", "total_spent": 5200, "orders": 8},
  {"id": 102, "email": "user2@example.com", "total_spent": 150, "orders": 1},
  {"id": 103, "email": "user3@example.com", "total_spent": 800, "orders": 3}
]'
```

**Output:**

```
segments: [
  {
    "segment_name": "VIP Customers",
    "count": 1,
    "users": [{"id": 101, "email": "user1@example.com", "total_spent": 5200, "orders": 8}]
  },
  {
    "segment_name": "Regular Customers",
    "count": 1,
    "users": [{"id": 103, "email": "user3@example.com", "total_spent": 800, "orders": 3}]
  },
  {
    "segment_name": "New Customers",
    "count": 1,
    "users": [{"id": 102, "email": "user2@example.com", "total_spent": 150, "orders": 1}]
  }
]
```

### Example 3: Segment by Demographics

**Input:**

```
users: '[
  {"id": 201, "name": "Emma", "age": 25, "country": "US", "plan": "premium"},
  {"id": 202, "name": "James", "age": 45, "country": "UK", "plan": "free"},
  {"id": 203, "name": "Sophia", "age": 28, "country": "US", "plan": "premium"}
]'
```

**Output:**

```
segments: [
  {
    "segment_name": "US Premium Users",
    "count": 2,
    "users": [
      {"id": 201, "name": "Emma", "age": 25, "country": "US", "plan": "premium"},
      {"id": 203, "name": "Sophia", "age": 28, "country": "US", "plan": "premium"}
    ]
  },
  {
    "segment_name": "UK Free Users",
    "count": 1,
    "users": [{"id": 202, "name": "James", "age": 45, "country": "UK", "plan": "free"}]
  }
]
```

## Common Use Cases

* **Targeted Marketing**: Segment users for personalized email campaigns, offers, and promotions
* **Customer Analytics**: Analyze user behavior patterns and identify valuable customer segments
* **Churn Prevention**: Identify at-risk users and create retention strategies
* **Product Personalization**: Customize product recommendations and user experiences based on segments
* **Pricing Strategy**: Segment customers by value to optimize pricing and upsell opportunities
* **Resource Allocation**: Prioritize support and engagement efforts based on user segments
* **A/B Testing**: Create user segments for controlled experiments and feature rollouts

## Error Handling

| Error Type              | Cause                                        | Solution                                                             |
| ----------------------- | -------------------------------------------- | -------------------------------------------------------------------- |
| Invalid JSON            | Users parameter is not valid JSON            | Verify the JSON syntax and ensure proper formatting                  |
| Empty User List         | Users array is empty                         | Provide at least one user object in the array                        |
| Missing Required Fields | User objects lack necessary attributes       | Ensure all user objects have required segmentation fields            |
| Invalid Data Type       | User field values are incorrect type         | Verify numeric fields contain numbers, strings contain text, etc.    |
| Segmentation Failed     | Cannot determine segments from provided data | Provide more distinctive user attributes for meaningful segmentation |
| Parse Error             | Cannot parse the users string                | Check for special characters or encoding issues in the JSON string   |

## Notes

* **Input Format**: The users parameter must be a JSON string representing an array of user objects. Each object should contain attributes for segmentation.
* **Segmentation Criteria**: The node analyzes user attributes automatically to determine meaningful segments. Provide rich user data for better segmentation.
* **Flexible Attributes**: User objects can contain various attributes (age, activity, purchases, demographics, etc.). More attributes enable more nuanced segmentation.
* **Segment Naming**: Segments are automatically named based on the distinguishing characteristics of users in each group.
* **Performance**: Large user lists may take longer to process. Consider batching very large datasets if needed.
* **Use Cases**: Combine this node with email, notification, or personalization nodes to act on segmented user groups.
* **Data Quality**: Better quality user data with clear attributes leads to more meaningful and actionable segments.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.agenticflow.ai/reference/nodes/segment_user.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
