---
title: "Compare"
description: "Evaluate two values with operators like equals, contains, and starts with — supports automatic type detection and case sensitivity."
icon: "scale-balanced"
---

The **Compare** step evaluates two values and returns `true` or `false`. Use it to build conditional branches in your agent — route a conversation based on a classification result, check whether a score exceeds a threshold, or verify that a date falls within range.

Compare automatically detects whether the values are numbers, dates, booleans, or strings and applies the appropriate comparison logic. No manual type casting required.

---

## Configuration

<Steps>
  <Step title="Left operand">
    The first value to compare. Accepts plain text or an expression like `{{Steps.Classifier.Value}}`.
  </Step>
  <Step title="Operator">
    The comparison to perform. See the full operator table below.
  </Step>
  <Step title="Right operand">
    The second value. Not required for `Is Empty` and `Is Not Empty` operators.
  </Step>
  <Step title="Case sensitive">
    Toggle for string comparisons. Off by default — `"hello"` matches `"Hello"`. Turn on when exact casing matters.
  </Step>
</Steps>

---

## Operators

<Tabs>
  <Tab title="Universal">
    These work with all detected types — numbers, dates, booleans, and strings.

    | Operator | What it checks |
    |---|---|
    | **Equals** | Left is exactly equal to Right |
    | **Not Equals** | Left differs from Right |
  </Tab>

  <Tab title="Ordering">
    These work with numbers, dates, and strings (lexicographic). They are **not valid for booleans** — the step will throw an error if both values are `true`/`false`.

    | Operator | What it checks |
    |---|---|
    | **Greater Than** | Left > Right |
    | **Greater Than or Equal** | Left ≥ Right |
    | **Less Than** | Left < Right |
    | **Less Than or Equal** | Left ≤ Right |

    For strings, ordering uses lexicographic comparison (dictionary order) and respects the case sensitivity toggle.
  </Tab>

  <Tab title="String-only">
    These only work when both values are strings. If the values are detected as numbers or dates, the step throws an error.

    | Operator | What it checks |
    |---|---|
    | **Contains** | Left string includes Right as a substring |
    | **Not Contains** | Left string does not include Right |
    | **Starts With** | Left string begins with Right |
    | **Ends With** | Left string ends with Right |

    All four respect the **Case sensitive** toggle.
  </Tab>

  <Tab title="Existence">
    These only inspect the left operand. The right operand is ignored.

    | Operator | What it checks |
    |---|---|
    | **Is Empty** | Left is null, whitespace, or an empty array `[]` |
    | **Is Not Empty** | Left has a non-empty value |
  </Tab>
</Tabs>

---

## Automatic type detection

Compare inspects both values and picks the best type in this order:

| Priority | Detected as | Example values | Notes |
|---|---|---|---|
| 1 | **Boolean** | `true`, `false` | Only Equals / Not Equals are valid |
| 2 | **Number** | `42`, `3.14`, `-100`, `1e-5` | Parsed as decimal for precision |
| 3 | **Date** | `2026-03-26T14:30:00Z` | ISO 8601 with timezone required |
| 4 | **String** | Everything else | Fallback — all operators available |

<Info>
  Type detection runs on the **resolved** values, not the raw expression text. If `{{Steps.Score.Value}}` resolves to `"85"`, it will be detected as a number, not a string.
</Info>

---

## Output

The step returns a **boolean**: `true` if the comparison passes, `false` if it does not.

Use the output to drive conditional routing downstream:

```
{{Steps.Compare.Value}}  →  true / false
```

---

## Use case: route by customer tier

An e-commerce agent receives an order and needs to apply different handling based on the customer's annual spend.

**Agent flow:**
```
Input → Fetch Customer (HTTP) → Compare → [Branch]
                                   ├─ true  → VIP Handler (AI Model)
                                   └─ false → Standard Handler (AI Model)
```

**Compare configuration:**

| Field | Value |
|---|---|
| Left | `{{Steps.Fetch_Customer.Output.Body.annualSpend}}` |
| Operator | Greater Than or Equal |
| Right | `10000` |
| Case sensitive | — (not applicable for numbers) |

When the customer's annual spend is 10,000 or more, the Compare step returns `true` and the agent routes to the VIP handler. Otherwise, it routes to the standard handler.

---

## Tips

<Tip>
  Combine Compare with a conditional `{{ if }}` block in a downstream prompt to act on the result:
  ```
  {{ if Steps.Compare.Value == 'True' }}
  This customer qualifies for priority support.
  {{ else }}
  Follow standard support procedures.
  {{ end }}
  ```
</Tip>

<Warning>
  String-only operators (`Contains`, `Starts With`, `Ends With`) will fail at runtime if the resolved values are detected as numbers or dates. If you need substring matching on a value that looks like a number (e.g., a product SKU like `"12345"`), ensure at least one value contains non-numeric characters so it falls through to string detection.
</Warning>
