---
title: CLAMP
url: https://www.tines.com/docs/formulas/functions/clamp/
kind: formula-function
---

*[tines.com](https://www.tines.com/llms.txt) › [Docs](https://www.tines.com/llms.txt) › [Formulas](https://www.tines.com/llm/docs/formulas.md) › [Functions](https://www.tines.com/llm/docs/formulas/functions.md)*

# CLAMP

*[View on tines.com](https://www.tines.com/docs/formulas/functions/clamp/)*

Restricts a given value to a specific range defined by a minimum and a maximum boundary. If the input value is lower than the minimum, the function returns the minimum. If it is higher than the maximum, it returns the maximum. Otherwise, it returns the input value itself. For string inputs, CLAMP uses lexicographical sort order.

**Categories:** Numbers, Text

## Syntax

```
CLAMP(input, min, max)
```

## Examples

### Example 1

Input:

```json
{
  "my_action": {
    "input": -10
  }
}
```

Formula:

```
CLAMP(my_action.input, 0, 100)
```

Output:

```json
0
```

### Example 2

Input:

```json
{
  "my_action": {
    "input": "blue"
  }
}
```

Formula:

```
CLAMP(my_action.input, "amber", "green")
```

Output:

```json
"blue"
```

## Sample actions

```json
{
  "standardLibVersion": "89",
  "actionRuntimeVersion": "72",
  "agents": [
    {
      "disabled": false,
      "name": "CLAMP",
      "description": null,
      "options": {
        "mode": "message_only",
        "loop": false,
        "payload": {
          "CLAMP_OUTPUT": "=CLAMP(my_action.input, 0, 100)"
        }
      },
      "position": {
        "x": 105,
        "y": 555
      },
      "type": "eventTransformation",
      "timeSavedUnit": "minutes",
      "timeSavedValue": 0,
      "monitorAllEvents": false,
      "monitorFailures": false,
      "monitorNoEventsEmitted": null,
      "aiMonitoringThresholds": [],
      "caseConfiguration": {
        "subStatus": null,
        "tags": []
      },
      "recordType": null,
      "recordWriters": [],
      "form": null,
      "createdFromTemplateGuid": null,
      "createdFromTemplateVersion": null,
      "templateTags": [],
      "originStoryIdentifier": "cloud:00e45749508fe15ca1af3397eab8db78:18f32aa494b49ac605dcc3aa0eda65cc"
    },
    {
      "disabled": false,
      "name": "My Action",
      "description": null,
      "options": {
        "mode": "message_only",
        "loop": false,
        "payload": {
          "input": 12
        }
      },
      "position": {
        "x": 105,
        "y": 450
      },
      "type": "eventTransformation",
      "timeSavedUnit": "minutes",
      "timeSavedValue": 0,
      "monitorAllEvents": false,
      "monitorFailures": false,
      "monitorNoEventsEmitted": null,
      "aiMonitoringThresholds": [],
      "caseConfiguration": {
        "subStatus": null,
        "tags": []
      },
      "recordType": null,
      "recordWriters": [],
      "form": null,
      "createdFromTemplateGuid": null,
      "createdFromTemplateVersion": null,
      "templateTags": [],
      "originStoryIdentifier": "cloud:00e45749508fe15ca1af3397eab8db78:18f32aa494b49ac605dcc3aa0eda65cc"
    }
  ],
  "sections": [],
  "links": [
    {
      "sourceIdentifier": "1",
      "receiverIdentifier": "0"
    }
  ],
  "diagramNotes": []
}
```
