Skip to main content

Overview

Use the custom_function task type to run your own Python scoring logic on each evaluation item, giving you full control over scoring beyond the built-in metrics. The function source code is extracted, sent to the API, and executed server-side in a sandboxed environment.
The scale-gp-beta SDK provides a CustomFunction helper that handles source extraction and serialization for you.

SDK Helper

The CustomFunction class wraps a Python callable and provides methods to serialize it for the API and test it with a dry run.
Any imports your function needs must be placed inside the function body. Module-level imports are not captured when the source is extracted and will not be available at execution time.

Allowed Imports

Custom functions run in a restricted environment. Only these standard library modules are available: math, json, re, collections, itertools, functools, random, decimal, datetime, copy, textwrap, difflib, unicodedata Imported modules expose only their public functions, classes, and constants, not their submodules. From random, only random.Random is available. Create it inside your function with an explicit, non-None seed (for example, rng = random.Random(42)); it supports choice, choices, randint, random, randrange, and sample. Module-level helpers such as random.random() are unavailable.

Return Type

Functions must return JSON-serializable values: finite numbers, booleans, strings, lists, objects, or None (JSON null). Non-finite numbers (NaN or infinity) and objects that cannot be serialized to JSON produce an error. Structured return values can also be materialized into separate result columns using configuration.outputs.

Using arg_mapping

By default, function parameter names are matched to dataset column names. Use arg_mapping when your function parameters don’t match the column names in your data:
Values that already start with item. are passed through unchanged, which lets you reference nested fields:

Dry Run

Test your function against sample data before creating a full evaluation. The dry run endpoint is synchronous — it executes your function inline and returns per-row results immediately.

Discovering Columns

If you already have an evaluation and want to see which columns are available for arg_mapping:

Example Usage

The following illustrates a complete example creating an evaluation with a custom function task.
You can also create evaluations using the raw task dict directly, without the SDK helper:

Structured Return Values

Use a raw task dictionary when you need separate result columns from a structured return value:
Poll for completion and inspect results:
Once the evaluation completes, you can also view the results — including per-item custom function scores — in the SGP UI.

Constraints