All guides

Code nodes

Objective. Run a small JavaScript or Python transformation with explicit flow inputs and return its result to the next node.

Prerequisites

  • A bot flow with variables available before the Code node.
  • A bounded transformation that can return a JSON result during a single flow turn.

Choose a supported language and write the result

  1. 1Add a Code node and open its editor. The flow schema accepts JavaScript and Python only; TypeScript is rejected.
  2. 2Write code that returns a JSON result. For example, return an object with the fields that the next flow step needs rather than formatting a message inside the code node.
  3. 3Use the Success edge for a returned result and the Error edge for a runtime failure. The engine records code_status, code_stdout, and, on failure, code_error for the following branch.

Declare inputs and outputs explicitly

  1. 1In Input mappings, give each code input a name and select the source flow variable. The code receives only these mapped values in its inputs object.
  2. 2Input names must be unique. Choose names valid in JavaScript and Python, such as customer_age, so a duplicate name cannot make the saved flow invalid.
  3. 3In Output mappings, map each returned JSON path to a flow variable. At least one output mapping is required, and every output path must be non-empty. Use distinct output variable names as an operating practice: mappings run in order, so reusing a variable can overwrite an earlier value.
  4. 4Use Test code with sample input values before saving. The test uses the current draft, so it lets you check the returned shape without changing the flow first.

Understand code-run usage

Code execution is metered at $0.003 per wall-clock second. Each execution is charged in whole seconds, rounded up, with a minimum of one second.

Expected result. The node has named inputs, a JSON result, at least one output mapping, and Success and Error branches that make the result usable by the rest of the flow.

Troubleshoot code nodes

The code reaches its time limit and follows the Error edge.
Keep the transformation bounded. Remove long loops or waiting work, return only the data the next node needs, and move external API calls into an HTTP Request node.
The saved flow reports an invalid language.
Choose JavaScript or Python in the code editor. TypeScript and other language labels are rejected by the flow schema.
The flow reports duplicate input names.
Rename the code-side input names so every mapping has a unique name. Source flow variables can still be chosen deliberately for each input.
The flow reports empty outputs or cannot save the code node.
Keep at least one output mapping and give every mapping a result path, such as score or customer.tier. Then map that path to the flow variable the next node will use.

Related guides