# Expressions

> Expressions let a node read data from the trigger and from earlier nodes. Write JavaScript between double braces in a node field and Sommatic AI evaluates it right before the node runs.

Source: https://docs.sommatic.ai/en/expressions/ (updated 2026-11-26)

Expressions connect the nodes of a workflow. With them a node reads the webhook body, the label an AI node chose, the
id of the run or today's date, and turns it into the value one of its fields needs: a URL, a condition, a message, an
object for the next step.

Diagram: An expression reads the run data right before the node runs, and its result becomes the value of the field.

## Syntax

An expression is JavaScript between double braces. It is evaluated when the node runs, and its result replaces it:

```javascript
{{ $json.body.email }}
{{ $('Classify request').item.json.label === 'billing' }}
{{ $now.setZone('America/Bogota').toFormat('yyyy-LL-dd') }}
```

Inside the braces you write one JavaScript expression: property access, operators, ternaries, method calls, arrow
functions. When you need several statements, wrap them in a function that you call at once (see
[recipes](https://docs.sommatic.ai/en/expressions/recipes.md)).

## Where expressions are evaluated

Sommatic AI evaluates expressions in the fields of a node's configuration: plain text fields and the text values nested in
objects and lists, such as the headers or the body of an `io.http` request. Evaluation happens right before the node
runs, so an expression sees every node that has already run in this execution.

Some fields use another language on purpose:

| Field                                                                                       | Language                      | Page                                                                  |
| ------------------------------------------------------------------------------------------- | ----------------------------- | --------------------------------------------------------------------- |
| `expr` of `data.transform`, and `expr` of `flow.if` or `flow.switch` written without braces | JSONata                       | [JSONata](https://docs.sommatic.ai/en/expressions/jsonata.md)         |
| `template` of `data.template`                                                               | Handlebars                    | [Handlebars](https://docs.sommatic.ai/en/expressions/handlebars.md)   |
| `schema` of `data.validate`                                                                 | JSON Schema                   | [JSON Schema](https://docs.sommatic.ai/en/expressions/json-schema.md) |
| `code` of `code.js` and `code.python`                                                       | JavaScript or Python programs | [Code nodes](https://docs.sommatic.ai/en/expressions/code-nodes.md)   |

## Pure and mixed fields

How the result is inserted depends on what else the field contains.

| Field value                    | Kind                                                                        | Result                                                                                                               |
| ------------------------------ | --------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `{{ $json.total }}`            | **Pure**: the whole value is one expression (spaces around it are allowed). | Keeps its type: number, boolean, object, list or `null`.                                                             |
| `Total: {{ $json.total }} USD` | **Mixed**: text with one or more expressions.                               | Always text. Objects and lists are inserted as JSON; `null` and `undefined` become the words `null` and `undefined`. |
| `Total`                        | Plain text                                                                  | Unchanged.                                                                                                           |

Use a pure field whenever the node expects something other than text: a boolean in `flow.if`, an object for a request
body, a number for a limit. To build an object, wrap it in parentheses:

```javascript
{{ ({ id: $json.id, received: $now.toISO(), run: $execution.id }) }}
```

## When an expression fails

- **Mixed field**: only the part that failed is replaced by `[ERROR: message]`, for example
  `Hello [ERROR: Cannot read properties of undefined (reading 'name')]`. The other parts resolve and the node does not
  fail, so read the node's output when a text looks wrong.
- **Pure field**: the field keeps its original text, `{{ … }}` unresolved, and the node receives that text. What
  happens next depends on the node: `flow.if` tries to read it as JSONata, fails and leaves through its `error` port;
  `io.http` would send the literal text. Guard reads that can fail with optional chaining (`?.`), `$ifEmpty` or a
  `try`/`catch`.

> **Note: 100 ms per expression**
>
> Each expression has 100 milliseconds to finish. One that takes longer fails like any other error. Loops over large
> lists, parsing or heavy math belong in a [code node](https://docs.sommatic.ai/en/expressions/code-nodes.md), which has its own, longer timeout.

## What an expression can use

- **Variables**: `$json`, `$input`, `$('Node label')`, `$execution`, `$workflow`, `$node`, `$now`, `$today` and
  `$uuid`. See [variables](https://docs.sommatic.ai/en/expressions/variables.md).
- **Helpers**: `$jmespath`, `$ifEmpty`, `$isEmpty`, `$slugify`, `$toQueryString`, `$base64Encode`, `$base64Decode`
  and `$randomId`. See [helpers](https://docs.sommatic.ai/en/expressions/helpers.md).
- **Libraries**: lodash as `_`, Luxon through `$now` and `$today`, and JMESPath through `$jmespath`.
- **JavaScript built-ins**: `Math`, `JSON`, `Date`, `String`, `Number`, `Boolean`, `Array` and `Object`, plus the
  methods of strings, numbers, lists and objects.

## Next steps

- [API reference](https://docs.sommatic.ai/en/expressions/reference.md): Every variable and helper with its signature, parameters, return value, errors and examples run against the engine.
- [Variables](https://docs.sommatic.ai/en/expressions/variables.md): Every variable, its type and an example.
- [Recipes](https://docs.sommatic.ai/en/expressions/recipes.md): Patterns that work in production, ready to copy.
- [Gotchas](https://docs.sommatic.ai/en/expressions/gotchas.md): The mistakes that break expressions and how to avoid them.
- [Nodes](https://docs.sommatic.ai/en/nodes.md): The fields of every node, where you write expressions.
