Skip to content
Corridor V1.26.03 is out, see what's new

Register a Utility Function

Ask AI
TL;DR
A Global Function is a reusable piece of Python (like a weighted_mean helper) that you register once and call by its alias from other objects, instead of copying it into each. Define it once and every object that uses it stays in sync. Write the function body, set an alias, and create.

A Utility Function / Global Function is a reusable piece of Python you register once and share across objects, instead of re-writing the same helper each time. In the platform it is called a Global Function. Once registered, select it in any object that accepts inputs and call it by its alias.

Global Functionweighted_mean
Data Elements
Features
Reports
Policies

For example, register weighted_mean once and call weighted_mean(values, weights) in every Report that needs it, so the calculation lives in one place instead of drifting across copies.

Follow these steps to register a Global Function.

On the Resources → Global Functions page, click + New Global Function.

The form opens with an editable name field at the top left (New Global Function). Type a descriptive name (for example, Weighted Mean) and confirm to land on the full form.

Set the Output Type (optional) - the type of value the function returns (for example, Numerical, String, Boolean).

Set the Alias * - the name used to call the function in code (for example, weighted_mean).

Click Add Arguments to define what your function takes in as input (for example, values and weights). Each argument becomes a variable you can use in the Definition.

Under Input, select any other Global Functions this one relies on, so you can call them by their alias inside the definition (for example, a roc_auc Global Function reused by another function like gini):

# Global Function: gini (alias: gini)
# Input: roc_auc <- another Global Function, selected here so it can be called by its alias below
return 2 * roc_auc(scores, labels) - 1

In the Definition editor, write the function body in Python. The arguments you defined are already in scope, so use them directly. Whatever the function returns is what callers receive when they call it by its alias. You can import standard libraries (numpy, math, datetime, etc.).

Write the logic directly, not wrapped in a def. The platform builds the function signature from the Alias and Arguments you set.

For example, the weighted_mean Global Function, using the values and weights arguments:

"""Return the weighted mean of values, or None if the weights sum to zero."""
total = sum(weights)
if not total:
return None
return sum(v * w for v, w in zip(values, weights)) / total

Fill in the Properties (Description and Group), then click Create at the bottom right. The Global Function is saved as a draft and you land on its details page.

To use a Global Function, select it in the Input or Resources section of any object that supports it, then call it by its alias in that object’s definition. It appears in code autocomplete inside the editor.

Next steps: