Skip to content

Function Node

The Function node runs custom JavaScript logic when a workflow needs deterministic data shaping, calculation, or routing support.

Use Function when the workflow needs predictable JavaScript logic instead of language reasoning. It is the right node for shaping data, calculating values, or preparing a deterministic result for the next step.

Choose Function when:

  • the workflow needs a calculation or transformation,
  • the output should be deterministic,
  • a later node needs cleaned or remapped data,
  • or an LLM-based decision would be too loose for the task.

Use AI Agent for natural-language reasoning and Tool for reusable external integrations.

  1. The node receives runtime context.
  2. The configured JavaScript executes.
  3. The return value becomes available to downstream nodes.
  4. Later nodes branch, respond, or call tools using that deterministic output.

Function is often the glue between extraction, routing, and external actions.

  • Code editor holds the JavaScript logic.
  • Label describes the role of the function on the canvas.

The code should be written with the downstream consumer in mind: what values must exist, what shape they should have, and what should happen if data is missing.

A common template is:

function execute(context) {
return {};
}
  • Normalize fields Convert extracted values into consistent casing, formatting, or shape.
  • Calculate priority Turn multiple signals into a deterministic score or category.
  • Build a payload Prepare JSON for a later Tool call.
  • Guard branch input Ensure If/else receives the exact values it expects.
  • A normalization function can trim and standardize extracted values before routing.
  • A small calculation function can return a value like parity or priority for downstream branching.
  • A producer-style function can use withStorage to expose structured output for later nodes to reference by slug.

The canvas view shows where the custom logic step sits in the branch.

Annotated Function node on the workflow canvas with entry and output ports

The inspector is where you write and review the deterministic logic that shapes downstream behavior.

Annotated Function node inspector showing the JavaScript code editor

  • Prefer Tool for external API calls so credentials and testing stay centralized.
  • Keep return values predictable and easy for downstream nodes to consume.
  • Handle missing context safely instead of assuming every field exists.
  • Test the full workflow path, not only the code snippet in isolation.

Should Function call external APIs directly? Prefer a Tool for external API calls so credentials, testing, and runtime messages stay centralized.

How should I debug a Function node? Test the workflow path and inspect runtime errors in the test panel or interaction execution details.