Requires version
0.8.61 or greater.
Example
-
Your pipeline has the following blocks:
load_data_from_api(data loader)clean_column_names(transformer)save_data(data exporter)
-
Then, you add the following callback block to your pipeline:
-
You associate the above callback block to the following 2 blocks:
load_data_from_api(data loader)clean_column_names(transformer)
-
When you run the pipeline, it’ll execute the
load_data_from_api(data loader) block first. It successfully completes. Then, the callback block will run and execute the functionhello_world. -
Next, the pipeline will execute the
clean_column_names(transformer) block. It fails due to some error. The callback block will run and execute the functionalert_me.
How to add callbacks to your pipeline
- Create a new pipeline or open an existing pipeline.
- Edit the pipeline.
- On the right side of the page, click the Add-ons icon in the navigation. If you don’t see it, try expanding the right area of the page.
- Click the button Callbacks.
- Click the button + Callback block.
- In the callback block’s code, add a function and decorate it with
@callback. You can have as many functions in a callback block as you want. - Use
@callbackor@callback('success')to decorate a function that should only run when the parent block successfully completes. - Use
@callback('failure')to decorate a function that should only run when the parent block fails.
Supported callbacks
success
Execute callback function when block runs successfully.
failure
Execute callback function when block fails.
cancelled
Available in versions
>= 0.9.77.Mage Pro callback features
Pipeline-level callbacks
In Mage Pro, callback blocks can be attached to the pipeline itself instead of only to individual parent blocks. Pipeline-level callbacks run once after a pipeline run reaches one of these terminal statuses:completedfailedcancelled
- Open the pipeline editor.
- Create at least one callback block from the Add-ons panel.
- In the callback block footer selector, choose the current pipeline UUID under Pipeline.
def success_callback(parent_block_data, **kwargs), the editor still shows the
current pipeline target. Saving that pipeline target shows a compatibility error because pipeline
callbacks do not pass parent_block_data or other block inputs. To use the callback at the pipeline
level, make block input arguments optional, for example
def success_callback(parent_block_data=None, **kwargs), use documented pipeline context keyword
arguments, or use a kwargs-only signature such as def success_callback(**kwargs). The original
required-argument signature remains valid for block-level callbacks.
You can also configure the same behavior in the pipeline metadata.yaml file or through the
pipeline create and update API:
Use
pipeline_run_id with existing authorized APIs or models if callback code needs additional
pipeline-run details.
Run details show each dispatched pipeline callback as a block run with its status and any
user-code error captured by the normal block-run execution path. Callback statuses can be
initial, queued, running, completed, or failed.
Advanced parameters
In Mage Pro, you can pass additional parameters to the@callback decorator.
fetch_inputs
By default, Mage will fetch upstream inputs before executing a callback.
If your callback doesn’t need input data (e.g. sending alerts, posting logs), you can disable input fetching to improve performance.
fetch_inputs=True(default) → Fetch parent block inputs before executing callbackfetch_inputs=False→ Skip fetching inputs, speeding up execution
Positional arguments
The 1st positional argument is the data output of the callback block’s parent block.Positional arguments are only supported in Mage versions
>= 0.8.81.Keyword arguments
Here are the keyword arguments that are available in each callback function:__input keyword argument
For versions
>= 0.8.81.__input in the callback function’s keyword arguments.
The value of the __input key is a dictionary. The keys in that dictionary are named after the
callback block’s parent block’s UUID.
For example, if the callback block’s parent block’s UUID is load_api_data, then this is how
you would access load_api_data’s data output:
Data integration pipelines only
The following keyword arguments are only available in callback functions with parent blocks in a data integration pipelines:Legacy
For versions
< 0.8.61.Adding a callback to your block
- Create a block as normal.
- In the top right of the block, click the triple dot icon which should open up a menu with more options. Click “Add callback”.
- You should now see another code editor under the main editor for your block.

- You can add an
on_successcallback and/or aon_failurecallback. These callbacks will run after your block run completes or fails. When you run your block in the pipeline edit page, it will also run the callback depending on the status of the block. - The callback function will be passed your pipeline’s runtime variables as keyword
arguments, so you can use the same
kwargs.get('<variable>')syntax in your callback.