What is a Code Step?
The Code Step is a flow tool that runs small, allow-listed Python snippets to validate data, update variables, and route the conversation. It runs on a normal tool step. Use it for the precise, deterministic work that an LLM shouldn’t guess at — format checks, counters, flag logic, and parsing structured data returned by a webhook.The run() Contract
Every Code Step must define exactly one top-level function named run:
- Must be named
runand take no arguments - Must return a
bool,list[bool], ortuple[bool, ...] - Must not use decorators, nested functions, or classes
- Must not use imports,
global, ornonlocal - Must only call allow-listed functions
Do not indent def run(): — it must start at the first column.
Variables and Inputs
Read and write configured variables with double-brace{{...}} placeholders, and pass extra values in as mapped inputs.
custom namespace, and input_1-style mapped inputs.
Compile and Run
The Code Step is validated twice — once at startup, and again before each execution:- Placeholders are rendered into executable Python
- The code is parsed and checked against the deny-by-default validator
run()executes and its return value is normalized into ordered boolean outputs
print(...) output are written to the call’s system notes, including the line number on failure. For example:
Useprint(...)for debugging: unquoted placeholders likeprint({{contact.email}})print the resolved value, whileprint("{{contact.email}}")prints the literal placeholder text.
Next Steps
- Allowed Functions — The full deny-by-default allow-list
- Examples — Common patterns and troubleshooting
- Routing — Return multiple booleans to branch
- Tool Steps — How tool steps and conditions work

