On this page
Sommatic Docs
Open portal

If Condition

Evaluates a boolean condition against the input payload to bifurcate the execution flow.

View as Markdown
Open in
Flow control Available flow.if Version 1.0.0 Execution: sync

Evaluates a condition and sends the unchanged payload through true or false.

This operator functions as a gateway that routes execution to either the 'true' or 'false' port based on the result of the configured expression. It supports two evaluation modes: the Sommatic AI Expression Engine ({{ }} syntax, full JavaScript via vm.Script) as the primary engine, and raw JSONata as a simpler fallback for expressions entered without {{ }}.

Behavior:

  • If the expression evaluates to a truthy value, execution proceeds through the 'true' port.
  • If the expression evaluates to a falsy value, execution proceeds through the 'false' port.
  • If 'treat_missing_as' is set to true and the expression yields undefined/null, it is treated as false.

How it works

  1. Resolves expr: a {{ }} is evaluated by the Expression Engine (JavaScript in an isolated context, 100 ms limit) with $json, $("Node"), $now and the other engine variables.
  2. If the resolved value is undefined, null or "", returns an error envelope without a port (see errors).
  3. A boolean is used as is.
  4. A string is evaluated as JSONata against the payload, where fields are referenced directly: amount > 1000, status = "active". This also applies to a {{ }} that returned a string, and to a {{ }} that failed in the engine (its raw text is then parsed as JSONata and fails).
  5. Any other type (number, object, array) cannot be compiled as JSONata and goes to error.
  6. Converts the result with !!result and sends the payload through true or false, with meta.evaluation { expr, result, raw_result } (expr is the original text).

In a workflow

The node as it appears in a workflow file (draft_nodes[]), and the envelope of a successful run.

{
  "node_id": "node-high-value",
  "label": "High value?",
  "operator_slug": "flow.if",
  "operator_version": "1.0.0",
  "config": {
    "expr": "{{ $json.amount > 1000 }}",
    "treat_missing_as": false
  }
}

Configuration

expr string Required Accepts expressions

An expression that must evaluate to a boolean. Wrap it in {{ }} to use the Sommatic AI Expression Engine (JavaScript) with variables like $json, $input or $("Node Name"), e.g. {{ $json.age >= 18 }} or {{ $json.status === "active" }}. Without {{ }} the text is evaluated as JSONata against the payload, where fields are referenced directly: age >= 18 or status = "active". $json is not bound in JSONata, so $json.age >= 18 without {{ }} always evaluates to false.

treat_missing_as boolean Optional

If enabled, undefined or null results from the expression will automatically route to the False port instead of throwing an error.

Default: false

Its configuration shows the shared execution settings, but this node does not apply retries (retryOnFail, maxTries) yet. continueOnFail is not applied by any node.

Behaviour in the code

What the implementation does with these keys beyond what the schema says.

expr
Without {{ }}, $json is not bound in JSONata: $json.amount > 1000 is always false. A {{ }} returning a string such as {{ $json.name }} is evaluated again as a JSONata path and is usually false.
treat_missing_as
Has no visible effect: undefined and null results always go to false, and nothing is thrown either way.

Output ports

true default

The condition is truthy.

Data
{
  "order_id": "ord_123",
  "amount": 1250,
  "status": "active"
}
false

The condition is falsy, including undefined and null JSONata results.

Data
{
  "order_id": "ord_124",
  "amount": 80,
  "status": "active"
}
error

JSONata compilation or evaluation failed.

Data
{
  "ok": false,
  "errors": [
    "Expression evaluation failed: path.charAt is not a function"
  ],
  "port": "error"
}

In expressions

What a later node can read from this node's output with $("If Condition").item.json.<path> (write your node's label instead of If Condition). Editor marks the paths the workflow editor suggests under Previous Nodes (the output contract); Worker marks the paths the worker really returns through true, from the output shown in Ports.

ExpressionEditorWorker
$("If Condition").item.json.payloadobjectThe worker does not return it: reads as undefined —
$("If Condition").item.json.order_idstringNot suggested by the editor= "ord_123"—
$("If Condition").item.json.amountnumberNot suggested by the editor= 1250—
$("If Condition").item.json.statusstringNot suggested by the editor= "active"—

— Editor: The editor suggests it, but the worker does not return it: it reads as undefined.

— Worker: The worker returns it but the editor does not suggest it: write it by hand. Keys inside objects can depend on your data or configuration (for example one key per label).

Errors

Message Port Cause and fix
Missing configuration: expr is required. out expr is empty or its {{ }} returned undefined, null or "" (for example {{ $json.flag }} on a missing field). The envelope has no port, so the engine routes it to out, which this node does not have: the branch stops silently. Compare explicitly, for example {{ $json.flag === true }}.
Expression evaluation failed: path.charAt is not a function error The {{ }} returned a number, object or array. Return a boolean, for example {{ $json.items.length > 0 }}.
Expression evaluation failed: <JSONata message> error Invalid JSONata, or a {{ }} with a JavaScript error whose raw text was then parsed as JSONata (for example Expected ":", got "}").

Input contract

payload object Optional

Output contract

payload object Optional

Contracts (JSON Schema)

The definition exactly as the orchestrator declares it. All is the whole *.definition.js; compare it with the sections above to spot differences between the documentation and the schema. Use it to validate a node before you publish.

{
  "slug": "flow.if",
  "name": "If Condition",
  "category": "flow",
  "description": "Evaluates a boolean condition against the input payload to bifurcate the execution flow.\n\n  This operator functions as a gateway that routes execution to either the 'true' or 'false' port based on the result of the configured expression. It supports two evaluation modes: the Sommatic AI Expression Engine ({{ }} syntax, full JavaScript via vm.Script) as the primary engine, and raw JSONata as a simpler fallback for expressions entered without {{ }}.\n\n  **Behavior:**\n  - If the expression evaluates to a truthy value, execution proceeds through the 'true' port.\n  - If the expression evaluates to a falsy value, execution proceeds through the 'false' port.\n  - If 'treat_missing_as' is set to true and the expression yields undefined/null, it is treated as false.",
  "capabilities": [
    "branching",
    "logic",
    "expression-engine",
    "jsonata"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "expr"
    ],
    "properties": {
      "expr": {
        "type": "string",
        "title": "Condition Expression",
        "description": "An expression that must evaluate to a boolean. Wrap it in {{ }} to use the Sommatic AI Expression Engine (JavaScript) with variables like $json, $input or $(\"Node Name\"), e.g. {{ $json.age >= 18 }} or {{ $json.status === \"active\" }}. Without {{ }} the text is evaluated as JSONata against the payload, where fields are referenced directly: age >= 18 or status = \"active\". $json is not bound in JSONata, so $json.age >= 18 without {{ }} always evaluates to false.",
        "format": "expression"
      },
      "treat_missing_as": {
        "type": "boolean",
        "title": "Treat Missing as False",
        "description": "If enabled, undefined or null results from the expression will automatically route to the False port instead of throwing an error.",
        "default": false
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    }
  },
  "input_contract_schema": {
    "type": "object",
    "description": "The JSON payload to be evaluated by the expression.",
    "properties": {
      "payload": {
        "type": "object"
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "description": "The original payload is passed through to the selected output port.",
    "properties": {
      "payload": {
        "type": "object"
      }
    }
  },
  "ports": [
    {
      "port_id": "true",
      "label": "True",
      "is_default": true,
      "supports_condition": true,
      "description": "Active when expression is true."
    },
    {
      "port_id": "false",
      "label": "False",
      "supports_condition": true,
      "description": "Active when expression is false."
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Active when expression evaluation fails."
    }
  ],
  "execution_mode": "sync",
  "tags": [
    "logic",
    "condition",
    "branch",
    "control-flow"
  ],
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}

Execution

Execution
sync
Stateful
No
Retries (retryOnFail)
No
Capabilities
branchinglogicexpression-enginejsonata
Tags
logicconditionbranchcontrol-flow

Notes and limits

  • meta is recorded in the run steps only: downstream nodes receive data as their payload and cannot read meta through $json or $("Node").
  • When the envelope has no data (or data is falsy), the engine stores the whole envelope as the node output: on error the next node receives { ok: false, errors: [...], port: "error" } as its payload.

Reviewed against the orchestrator code · 31e874b · 2026-11-26

Install agent tools

Give your coding agent the official Sommatic AI docs: skills, the docs MCP server and Markdown pages, so it never has to scrape the site.

Skills only. They do not update by themselves; run it again to refresh.

npx skills add https://docs.sommatic.ai
How agents read these docs