We use cookies

We use cookies to ensure you get the best experience on our website. For more information on how we use cookies, please see our cookie policy.

By clicking "Accept", you agree to our use of cookies.
Learn more.

GuideEvent TriggersEvent Filters

Event Filters

Events can be filtered in Hatchet, which allows you to push events to Hatchet and only trigger task runs from them in certain cases. If you enable filters on a workflow, your workflow will be triggered once for each matching filter on any incoming event with a matching scope (more on scopes below).

Basic Usage

There are two ways to create filters in Hatchet.

Default filters on the workflow

The simplest way to create a filter is to register it declaratively with your workflow when it’s created. For example:

In each of these cases, we register a filter with the workflow. Note that these “declarative” filters are overwritten each time your workflow is updated, so the ids associated with them will not be stable over time. This allows you to modify a filter in-place or remove a filter, and not need to manually delete it over the API.

Filters feature client

You also can create event filters by using the filters clients on the SDKs:

⚠️

Note the scope argument to the filter is required both when creating a filter, and when pushing events. If the scope on filter creation does not match the scope provided when pushing events, the filter will not apply.

Then, push an event that uses the filter to determine whether to run. For instance, this run will be skipped, since the payload does not match the expression:

But this one will be triggered since the payload does match the expression:

In Hatchet, filters are “positive”, meaning that we look for matches to the filter to determine which tasks to trigger.

Accessing the filter payload

You can access the filter payload by using the Context in the task that was triggered by your event:

Advanced Usage

In addition to referencing input in the expression (which corresponds to the event payload), you can also reference the following fields:

  1. payload corresponds to the filter payload (which was part of the request when the filter was created).
  2. additional_metadata allows for filtering based on additional_metadata sent with the event.
  3. event_key allows for filtering based on the key of the event, such as user:created.