Code Execution¶
Code steps let you run custom Python inside a workflow. They’re useful when you need deterministic logic or data shaping that’s hard to express with standard connected-app actions alone.
Code runs in an isolated execution environment and can be tested from the workflow editor before you run a workflow live.
When To Use Code Steps¶
Common reasons to add a code step:
- Parse or reshape data (JSON, CSV-like text, lists)
- Apply business rules (filtering, scoring, routing)
- Format outputs for downstream steps (templates, strings, numeric formatting)
- Combine multiple step outputs into one structured payload
If you can do the same work with a standard integration step, that is usually simpler to maintain. Use code when you need precision.
How Inputs And Outputs Work¶
Inputs¶
Code steps can access outputs from previous steps. In many workflows, prior step outputs are provided as variables derived from step IDs, for example:
previous_result(when a single upstream result is available)<step_id>_result(where<step_id>is converted into a valid Python identifier)
The editor also shows “available data” chips to help you insert the right variables.
Output¶
Your code should assign a value to a variable named result. That value becomes the output of the code step for later steps to use.
Example:
import json
data = json.loads(previous_result)
result = {
"email": data.get("email"),
"company": data.get("company"),
}
Testing Code In The Editor¶
From the code tab in the node drawer, you can run a Test using mock values. This helps you validate the code compiles, your variable references are correct, and the produced result is what you expect.
If a test fails, the editor will show the error message so you can correct it before running a full workflow.
Tips¶
- Keep each code step small and focused.
- Treat inputs as untrusted: use
.get(...), validate types, and handle missing fields gracefully. - Use Virtual Run to preview the full workflow behavior after changing code steps. See Virtual Run Preview.