# Ports and envelope

> Every node returns an envelope with ok, data, port and meta. The data becomes the next node's input, and the port decides which edges the engine follows. This page covers ports, edges, fan-out and how the final port settles a run.

Source: https://docs.sommatic.ai/en/workflows/ports-and-envelope/ (updated 2026-11-26)

A workflow does not branch by magic. Each node says what happened by naming a port, and the graph says where each port
leads. Read this page and you can predict any run from its graph.

## The envelope

When a node finishes, it returns an envelope:

```json
{
  "ok": true,
  "data": { "label": "billing", "confidence": 0.92 },
  "port": "out",
  "meta": {}
}
```

| Field  | Meaning                                                                                                                    |
| ------ | -------------------------------------------------------------------------------------------------------------------------- |
| `ok`   | Whether the node did its work.                                                                                             |
| `data` | The node's output. It becomes `$json` for the next node and stays available to every later node through `$('Node label')`. |
| `port` | The outcome. The engine follows the edges that leave this port. When a node returns no port, the engine uses `out`.        |
| `meta` | Extra information about the execution (for example, which cases matched in `flow.switch`).                                 |

In a run, each node leaves a node execution with its output, port, status and duration, so you can see later which
port every node chose.

## Ports

Each node declares its ports in the [catalog](https://docs.sommatic.ai/en/nodes.md). One of them is the default. Some common sets:

| Node                                                                                                    | Ports                                            |
| ------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
| Most nodes (`io.http`, `data.transform`, `code.js`…)                                                    | `out`, `error`                                   |
| [`flow.if`](https://docs.sommatic.ai/en/nodes/flow.if.md)                                               | `true`, `false`, `error`                         |
| [`flow.switch`](https://docs.sommatic.ai/en/nodes/flow.switch.md)                                       | one port per case you define, `default`, `error` |
| [`data.validate`](https://docs.sommatic.ai/en/nodes/data.validate.md)                                   | `valid`, `invalid`, `error`                      |
| [`data.lookup`](https://docs.sommatic.ai/en/nodes/data.lookup.md)                                       | `found`, `miss`, `error`                         |
| [`ai.classify.triage`](https://docs.sommatic.ai/en/nodes/ai.classify.triage.md)                         | `success`, `error`                               |
| [`integrations.mongodb.operation`](https://docs.sommatic.ai/en/nodes/integrations.mongodb.operation.md) | `out`, `empty`, `error`                          |
| [`human.task.create`](https://docs.sommatic.ai/en/nodes/human.task.create.md)                           | `created`, `error`                               |
| [`flow.split`](https://docs.sommatic.ai/en/nodes/flow.split.md)                                         | `out` (once per item), `done`, `error`           |
| [`flow.try`](https://docs.sommatic.ai/en/nodes/flow.try.md)                                             | `do`                                             |

> **Warning: A node continues only through a port it actually returns**
>
> The ports in the catalog are what a node declares. A few nodes do not return their declared success port yet (for
> example `ai.classify`, `ai.extract` and `ai.prompt`), and some secondary ports are never returned (the `timeout` of
> `flow.join`, the `throttled` of `flow.rate.limit`, the `miss` of `ai.vector.search`). An edge from a port the node
> never returns never fires. Check the status note on the node's page before you wire a branch to it.

A port with no edge is a valid end: when a node leaves through a port that has no edge, that branch stops there.

## Edges

An edge connects a port of one node to another node:

```json
{
  "from": { "node_id": "validate", "port": "valid" },
  "to": { "node_id": "route", "port": "in" }
}
```

The studio writes `to.port` as `in`; the engine only looks at `from.node_id` and `from.port`. An edge whose
`from.port` is `*` is followed whatever port the node returns.

## Fan-out

Several edges can leave the same port. The engine runs every target, one after the other, and each branch receives the
same `data`. Branches run in the order their edges appear in the graph, and the engine runs one step of each branch
before going deeper into any of them.

A node that two branches reach runs once per branch. To gather the items produced by [`flow.split`](https://docs.sommatic.ai/en/nodes/flow.split.md),
use [`flow.join`](https://docs.sommatic.ai/en/nodes/flow.join.md), which waits for the `done` signal and collects the results.

## Passing data along

Ports that only route, such as those of `flow.if` and `flow.switch`, pass the input through unchanged: the next node
sees the same `$json` the router received. Nodes that do work replace `$json` with their own output, so read older
data with `$('Node label').item.json`. See [Expressions](https://docs.sommatic.ai/en/expressions.md).

## How the final port settles the run

When no edge is left to follow, the run ends. Its status depends on how it ended:

- **`failed`** if a node raised an error the engine could not route, if the run went over 100 steps, or if the last
  node that ran left through `error`.
- **`completed`** otherwise, including runs where a node failed, left through `error` and an edge on that port
  recovered the case.

> **Tip: Connect the error port where it matters**
>
> A node that fails and has an edge on its `error` port lets you notify someone, open a task or try a fallback, and the
> run can still end `completed`. See [Errors](https://docs.sommatic.ai/en/workflows/errors.md).

## Next steps

- [Errors](https://docs.sommatic.ai/en/workflows/errors.md): The error port, flow.try and what the engine does when a node fails.
- [Flow control nodes](https://docs.sommatic.ai/en/nodes/family/flow.md): if, switch, split, join and the rest of the family.
- [Variables](https://docs.sommatic.ai/en/expressions/variables.md): $json, $('…'), $execution and the others.
