# Filter

The **Filter** tool is a step that lets you stop your workflow based on the conditions you set. A Filter is different than a [Path](https://docs.getmesa.com/tools/paths) because it controls whether or not your workflow continues. A Path continues the workflow for a different outcome based on the conditions set.

You should use a Filter in your workflow when there are certain reasons why you would want your workflow to stop or continue or to only act on specific items or instances.

## Configure

When using the Filter tool, you will need to select the correct [variables](https://docs.getmesa.com/workflow-builder/fields/variables) so that MESA can apply the filtering based on the data returned by the previous steps of your workflow.

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2FuNEmArotXS9kjC1IVIB1%2Fimage.png?alt=media&#x26;token=2560b0a4-1593-4d01-a668-001a7663c3f9" alt=""><figcaption></figcaption></figure>

## Examples of Conditions <a href="#examples" id="examples"></a>

The Filter tool has nineteen conditions you can use to compare values.

<table data-full-width="true"><thead><tr><th>Condition</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td>Equals</td><td>A specified field matches an exact value provided</td><td>The number of line items in an order is equal to 2</td></tr><tr><td>Does not equal</td><td>A specified field does not match an exact value provided</td><td>The number of line items in an order is not equal to 2</td></tr><tr><td>Contains</td><td>A specified field includes a certain value within its content, regardless of its position in the text</td><td>An order's tags contains a "VIP" tag</td></tr><tr><td>Does not contain</td><td>A specified field does not include a certain value within its content, regardless of its position in the text</td><td>An order's tags does not contain a "VIP" tag</td></tr><tr><td>Is empty </td><td>A specified field has no data, meaning it is blank or null</td><td>An order's tags are empty</td></tr><tr><td>Is not empty</td><td>A specified field has data, meaning it is not blank or null</td><td>An order's tags are not empty</td></tr><tr><td>Is greater than</td><td>A specified field is numerically higher than a given value</td><td>A customer's order count is more than 2</td></tr><tr><td>Is less than </td><td>A specified field is numerically lower than a given value</td><td>A customer's order count is less than 2</td></tr><tr><td>Is less than or equal to</td><td>A specified field is numerically lower than or exactly equal to a given value</td><td>A customer's order count is less than or equal to 2</td></tr><tr><td>Is greater than or equal to</td><td>A specified field is numerically higher than or exactly equal to a given value</td><td>A customer's order count is greater than or equal to 2</td></tr><tr><td>Is in</td><td>A specified field matches any one of the values within a defined list or content</td><td>US is in a customer's country code address</td></tr><tr><td>Is not in</td><td>A specified field does not match any one of the values within a defined list or content</td><td>US is not in a customer's country code address</td></tr><tr><td>Starts with</td><td>A specified field value starts with a specific, or sequential, numbers or characters</td><td>A product's SKU starts with 123</td></tr><tr><td>Does not start with</td><td>A specified field value does not start with a specific, or sequential, numbers or characters</td><td>A product's SKU does not start with 123</td></tr><tr><td>Ends with</td><td>A specified field value ends with a specific, or sequential, numbers or characters</td><td>A product's SKU ends with XYZ</td></tr><tr><td>Does not end with</td><td>A specified field value does not end with a specific, or sequential, numbers or characters</td><td>A product's SKU does not end with XYZ</td></tr><tr><td>Is after [date/time]</td><td>A specified date/time value falls later than a given date or time</td><td>An order was created after 10/24/24 12:00AM</td></tr><tr><td>Is before [date/time]</td><td>A specified date/time value is earlier than a given date or time</td><td>An order was created before 10/24/24 12:00AM</td></tr><tr><td>Is on [date]</td><td>A specified date value matches exactly with a given date</td><td>An order was created on 10/24/24</td></tr></tbody></table>

When using dates or time frames as a condition or rule within the Filter step, you have the ability to use [specific date formats](https://docs.getmesa.com/workflow-builder/fields/liquid-templating#date).&#x20;

{% hint style="info" %}
Please note that values will be case-sensitive
{% endhint %}

## Going Further <a href="#multiple" id="multiple"></a>

### Multiple rule sets <a href="#multiple" id="multiple"></a>

You can apply additional rules by clicking the **More fields** button, then selecting the Additional Rules checkbox.

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2FWwx31eOiCGTpuUuQiBpD%2Fimage.png?alt=media&#x26;token=c3709b06-8d05-4299-9111-fbd3d63e2b25" alt=""><figcaption></figcaption></figure>

Define if all rules need to match (`AND`), or if only one of your rules needs to match (`OR`). You can add an unlimited number of rule sets by clicking the Add Rule button to build complex comparison logic.

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2FKW5KG1gHrhsGGv0saCy0%2Fimage.png?alt=media&#x26;token=f76c643e-3fb6-4ab3-85fd-1a9c0e2e116b" alt=""><figcaption></figcaption></figure>

## Technical Notes

### Advanced rule sets <a href="#advanced" id="advanced"></a>

If you use a combination of **AND** or **OR** operators, the logic will read from top to bottom. For example, `a AND b OR c AND d` will be executed as `((a && b) || c) && d`.&#x20;

#### **AND Filter will only** proceed if *both* conditions are true.

* **Example**: Order created is more than $5 **AND** it is the customer's first order.&#x20;
* **Action**: If both conditions are met, the task continues. Otherwise, it stops.

**OR Filter will proceed if at least&#x20;*****one*****&#x20;of the listed conditions is true**

* **Example**: Order created is more than $5 **OR** it is the customer's first order.&#x20;
* **Action**: If one condition is met, the task continues. Otherwise, it stops.

For more fine-grained control, separate your **AND** comparisons and **OR** comparisons into separate Filter steps.

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2FYfeZqS7refONdWYmXZ0D%2Fimage.png?alt=media&#x26;token=79e741f5-83bb-41cd-84e3-3fa12a018e87" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2F9DKfATcpB1i40nBMTBND%2Fimage.png?alt=media&#x26;token=8c63d70f-ba61-43a7-8792-0cf45ca1ef5d" alt=""><figcaption></figcaption></figure>

### Special values

The following values will be automatically cast from strings to their respective types:

* `true`
* `false`
* `null`

### Creating a custom comparison

You can further adjust the functionality of a Filter step by opening the step options (three vertical-dot icon) and clicking Edit code.

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2FT0v6Dp1bYFVe7OagRUEA%2Fimage.png?alt=media&#x26;token=db75f368-a743-4589-847b-8d9ba2725e52" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2FxNXGk7XWo182gx6JML3W%2Fas-edit-filter-code.png?alt=media&#x26;token=a57e53f3-d775-45f6-bd2d-c2d94d2272ca" alt=""><figcaption></figcaption></figure>


---

# 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.getmesa.com/tools/filter.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.
