- Receives workflow variables as input (through an input dictionary).
- Executes your defined Python logic.
- Returns any new or modified values as output (through an output dictionary).
Currently, Code Blocks only support Python
When to Use
Understanding when to use a Code Block helps you unlock its full potential in building smart, adaptive flows:- Custom Logic Execution – Use it to calculate, compare, or transform varaibles dynamically.
- Conditional Workflows – When decisions depend on complex logic that goes beyond standard Flow conditions.
Setup
In this example, we will demonstrate how the Code Block is used inside a workflow for a fictitious store. The goal is to automatically transfer customers to their nearest store based on the ZIP code provided during a call.1
Add a New Block
From your workflow canvas, click the + icon and select Code from the list of available blocks.The block will appear in your flow, ready for configuration.

2
Configure Input Variables
Each Code Block begins with one or more input variables, these are values passed into your script from previous blocks.Enter the name of the variable. This is the name that you will use to refer to the variable in your code.
Once you have entered the variable name set the variable itself. There are two of ways to do this:

Auto-gather
Automatically prompt the caller when a block needs specific information (e.g., name, email, or date). Phonely collects this input in real time no extra Talk block required.Variables from Previous Blocks
Use information already gathered earlier in other flows.For example, in this workflow, the AI first asks the caller why they’re calling. If the caller requests a store transfer, they’ll be prompted to provide their zip_code. This value can then be used as an input variable within the Code Block.3
Write Your Code
4
How It Works
Now, let’s break this down step-by-step to understand exactly what happens when this block runs inside your workflow.Function DefinitionEvery Code Block in Phonely starts with a function definition like this.
This is a lookup table that links each ZIP code to the corresponding store’s phone number.This line performs the lookup.Here, the result is stored in a dictionary with a key name, “store_phone_number”.
This key becomes the variable name that other workflow blocks can reference later.
For example, in a Transfer Block, you could select store_phone_number to automatically route the caller to the correct store.Returning the ResultFinally, the function returns the dictionary to Phonely. From this point, the output variable store_phone_number becomes available to all downstream blocks
- input_dict represents all variables passed into this block from earlier steps in the workflow.
- The function returns another dictionary that becomes the output, feeding data to the next blocks.
- The -> dict type hint simply means the function returns a dictionary.
This is a lookup table that links each ZIP code to the corresponding store’s phone number.
- If a customer provides ZIP code 12345, the workflow will know to call +1-555-123-4567.
- If the ZIP code is 10001, it will return +1-555-002-352 instead.
- It searches the dictionary for the customer’s zip_code value (captured earlier in the workflow).
- If it finds a match, it retrieves the store’s phone number.
- If the ZIP code isn’t recognized, it falls back to a default number — in this case, +1-444-504-6273, which might be your main support or general customer service line.
This key becomes the variable name that other workflow blocks can reference later.
For example, in a Transfer Block, you could select store_phone_number to automatically route the caller to the correct store.Returning the Result
5
Validate Your Code
After entering your Python code, click Validate Code to ensure it’s syntactically correct.
If validation passes, a green checkmark appears next to the Cofigure tab name, and the Continue button activates.Click Continue to proceed to the testing step.
If validation passes, a green checkmark appears next to the Cofigure tab name, and the Continue button activates.Click Continue to proceed to the testing step.

6
Test the Block
Once you’ve written and validated your Python function, you can test it directly from the Test tab. This step allows you to make sure the logic behaves exactly as you expect before you connect it to other workflow components.To do this, simply enter the respective values of the input variables into the test input field and observe the results when you click the Test button.
7
Use Output Variables
After the Code Block has been validated and tested to produce the expected results, you can connect other flows to it.Each time the code flow runs, all returned data is automatically made available as variables for the subsequent flows.These variables can then be referenced in later blocks - such as Transfer, Send SMS, or Email etc.In the above example we can:
- Add a Transfer Block.
- Set the Phone Number field to the variable store_phone.
-
Such that when triggered, the agent automatically transfers the caller to the correct store.


