Skip to content
Agentic Workflowdocs
v0.8.2Install free

concepts / data

Processing data with code

When a mapping isn't enough, reshape items with Python in the Code node.

Most changes need no code: drag a field, write an expression, or use Edit Fields. Use the Code node when you need to:

  • regroup or count values, for example orders per customer;
  • parse an unusual format with Python’s standard library (re, json, csv, datetime);
  • combine several fields with logic that doesn’t fit in one expression.
Code to Execute
words = input.get("text", "").split()
{
"words": len(words),
"longest": max(words, key=len) if words else "",
}
  • input is a normal Python value: a dict, a list or a single value.
  • The last line, on its own, is what the node passes on. An assignment on the last line returns nothing.
  • The next step reads it as {{ $input.result.words }}.
  • print() writes to the run’s activity log, which helps when you debug.

With several steps connected to the Code node, input is a dict keyed by each step’s label, such as input["Get Selected Text"]["selection"].

When the previous step outputs several items, the Code node runs once per item and input is one item. To work on the whole list at once (to total it or group it), put Aggregate in front of the Code node. It then receives one item that holds the list.

Code to Execute, after Aggregate (Put Output In Field: orders)
totals = {}
for order in input["orders"]:
totals[order["customer"]] = totals.get(order["customer"], 0) + order["amount"]
totals

Each run starts clean in an isolated sandbox: no network, no access to the page or your stored data, and a 30-second time limit. The first run after a pause takes a couple of seconds while Python starts. To call an API, use Http Request before or after the Code node.

The output is null

The last line is an assignment (total = 3) or a statement, so nothing is returned. Put the value on its own as the last line (total).

The Code node ran once per row but you wanted one total

It received a list of items, so it ran for each one. Add Aggregate before it.

input[“title”] raises a KeyError

Several steps are connected, so input is keyed by step label, or the field is missing on this item. Use input.get("title", ""), and check the shape in the previous step’s Output tab.

Ask Aria