Functions¶
One registry serves every resolver (§5). A function takes at most the listed arguments; a missing optional argument takes its default.
Function |
Arguments |
Returns |
|---|---|---|
|
|
the value at |
|
|
string |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
one or more |
string |
|
|
|
|
two or more |
the first argument with a value, with its JSON type |
|
|
the column’s distinct values, in order: |
|
|
the value at that row and column |
|
|
the rows as a JSON text: |
|
|
the parsed JSON value |
|
|
|
|
|
|
Examples use at = 2026-05-03T01:30:00Z.
The time a function computes from¶
Every built-in function depends only on its arguments, never on the context
(get_secret aside: it checks keys against the context’s tenant). The date
functions compute from the time in their last argument, at, converted to
timezone:
@{get_start_date_last_month, Europe/Oslo, run.logical_at} from the run's logical time
@{get_start_date_last_month, Europe/Oslo, '2026-03-01T00:00:00Z'} from a fixed time
@{get_start_date_last_month, Europe/Oslo} from the current time
Pass the time the run is for (in a pipeline,
run.logical_at: the schedule tick, a backfill date, or the trigger time) wherever a data window must be stable: every stage and retry of the run then gets the same value. Withoutatthe function uses the current time, which differs between retries, stages, and backfills.atis an RFC 3339 timestamp withZor an offset and at most six fractional digits; anything else is anargumenterror (checked byvalidatefor a literal). Quote a literal ('2026-03-01T00:00:00.5Z') so a dot is not read as a path. A reference with no value is a missing argument (missing_value;coalesceskips it).get_iso_timestamp_nowandget_unix_timestamp_nowalways use the current time: use them for request signing or expiry, not for data windows.
Arguments¶
timezoneis an IANA name, case-sensitive (Europe/Oslo). An unknown name is anargumenterror.Arguments may be references:
@{get_hour, owner.settings.tz, run.logical_at}. A reference argument must resolve to a string.get_previous_houris one elapsed hour beforeat, so across a DST change it can equalget_hour(autumn) or skip an hour (spring).str_joinconcatenates its arguments with no separator. A reference argument is rendered as text (true,7,2.0); an object or array is atypeerror. If the result is empty it is a missing value.
coalesce¶
coalesce is the only way to give a default. It reads its arguments left to
right and returns the first one that has a value; later arguments are never
read. If every one is missing it fails with missing_value.
@{coalesce, owner.settings.tz, Europe/Oslo} owner's tz, else Europe/Oslo
@{coalesce, owner.settings.tz, variables.tz, UTC} a chain
@{coalesce, execution.name, 'manual run'} quote literals with spaces or commas
Only a missing value moves on: no such path,
null,"", or blank. Every other error is raised when the argument is read: a namespace the context does not have (unknown_namespace, so a typo likeownr.xnever falls back), a provider that fails, atypeerror.Only the last argument may be a literal, and it must not be blank. A literal always has a value, so anything after it would never be read, and a blank one (
'') never is a value.@{coalesce, UTC, owner.settings.tz}and@{coalesce, owner.settings.tz, ''}areargumenterrors, fromvalidateand when resolved.Quote a default that contains a dot:
'data.csv','v1.2','s3.eu-west-1.amazonaws.com'. Bare,data.csvis a reference to a namespacedata. Arguments after the first value are never read, so such a mistake, or a typo in a later reference, passesvalidateand only fails on the run where the earlier arguments are missing. Test the fallback path too.Types: a reference keeps its JSON type, as a plain reference does. A literal is always a string, so
@{coalesce, owner.settings.periods, 12}gives the owner’s12(a number) or"12"(a string). For a typed default, declare it as a variable and refer to it:"variables": {"periods": 12}, "read": {"periods": "@{coalesce, owner.settings.periods, variables.periods}"}
Declaring defaults as variables also keeps them in one place.
Embedded in text and in SQL it works like any placeholder: the result is rendered as text or as a SQL literal, and a value holding a secret is refused in SQL.
Don’t default what picks a tenant’s data or a secret path (a company key, a vault key): a missing owner setting there should fail, not quietly read something else.
lookup¶
@{lookup, owner.settings.tz} the same as @{owner.settings.tz}
@{lookup, owner} the whole owner object
@{lookup, owner.settings.company_no, str} "1234": text, even as the whole string
owner: @{lookup, owner, json} owner: {"id":"o1","settings":{…}}
export_@{lookup, owner.settings.company_no}.csv export_1234.csv
@{lookup, owner.settings.tz, UTC} Europe/Oslo, or UTC when owner has no tz
@{lookup, owner.settings.n, 0, str} the default, then the format
@{lookup, owner.settings.retries, 3, int} the value, or the number 3
lookup is a reference written as a call: @{owner.x} is short for
@{lookup, owner.x}, and the two are the same placeholder. It is the only
way to read a whole namespace: without a dot, @{owner} is a call to a
function owner.
The first argument is a path, read as it is written, not resolved first:
@{lookup, variables.field}is the value ofvariables.field, never the value at the path it holds. A bare name is the whole namespace. The path cannot be quoted (@{lookup, 'owner'}is asyntaxerror); quote a key inside it as in any reference (owner.settings.'company.key').Without a format it behaves exactly as the reference: the whole string keeps the value’s JSON type, and inside a longer string the value is its text, so it builds file names and labels. An object or array in a longer string is a
typeerror.str: the value’s text, even when the placeholder is the whole string (1234becomes"1234",truebecomes"true"). An object or array is atypeerror.int,float,bool: the value as that JSON type, also as the whole string. The value must be that type or text that spells it ("3","2.5","true"); nothing is guessed, so"yes"is not a boolean.intalso takes a wholefloat(4.0). Anything else is atypeerror. The default is read as that type, and one that is not is anargumenterror when the placeholder is read.json: compact JSON, non-ASCII escaped, for any value: an object, an array, a string (quoted:"o1"), a DataFrame as its rows (asdataframe_to_json_arraygives them), also inside an object or array (@{lookup, tasks.<id>, json}). Use it to put an object in text.default: the text read when there is no value (a missing path,null, or blank). It is written out, never a placeholder, and is always a string, whatever the format; quote it to include,or}('a, b'). It is not blank. Any other error, such as an unknown namespace, is still raised. For a default that is itself read, usecoalesce. A last argument that isstr,json,int,floatorboolis the format, so those words cannot be a default. A default is text unless the format types it.Without a default, a missing path,
null, or blank ismissing_value, as for any reference. More than one default, or an argument that is neither a default nor a format, isargument; no argument, or more than three, isarity.taskscannot be read whole: it holds every task’s output, so@{lookup, tasks}isargument. Name the task:@{lookup, tasks.<id>}.At a SQL path the result is a literal like any other value; one that contains a secret this context read is refused.
As an argument of another function,
@{lookup, …}is the reference itself:@{get_secret, @{lookup, owner.settings.client_key}}is@{get_secret, owner.settings.client_key}, and with a format the argument is the formatted value (@{str_join, @{lookup, owner, json}}). Its own path, default and format are written out, never nested placeholders (argument). A service cannot add a function calledlookup.
Tables and values¶
These behave as ds-workflow-manager’s builtins of the same names, so a
workflow keeps working when it moves to standard.
@{get_column_as_list, account_id, tasks.read.output} distinct ids, in order
@{get_value_from_dataframe, 0, total, tasks.sum.output} row 0's total
@{is_empty, tasks.read.output} true for no rows
@{json_parse, variables.config_json} the parsed object
A table is a JSON array of objects, or a pandas
DataFrame. The package does not depend on pandas: it recognises a frame by its interface and reads it through that (a column, a cell), without converting the whole frame. A frame whose column names are not unique as text (atwice, or0and"0") is anargumenterror.get_value_from_dataframereads a DataFrame’s row by its index label, as the manager does (after a filter, the labels keep their gaps), and an array’s by position. The index is an integer, or text or a number that is one (2,"2",2.0);1.9is anargumenterror. A frame whose row labels repeat, or have several levels, is anargumenterror.get_column_as_listreturns each value once, in order, as the manager’s does. Numbers are equal by value (1and1.0are one); a boolean is not a number.dataframe_to_json_arraywrites compact JSON with non-ASCII escaped, the same text for a DataFrame and for an array of the same rows, with column labels as text ({"0": …}for a frame without a header). Unlike the manager’s pandasto_json:/is not escaped, floats are written in full (0.30000000000000004), and timestamps are ISO 8601 text, not epoch milliseconds. A consumer that parsed epoch numbers must change when its workflow moves tostandard.Arguments are passed as values, not only strings: a reference argument may hold a table, a list, or an object.
nullor blank, from a reference or a literal (''), is passed as no value (is_emptyof it istrue,json_parseof it ismissing_value). A literal is always text:nullis the four letters. A path that does not exist ismissing_value, as for any reference.Results are plain JSON: numpy values become Python ones (arrays lists),
NaN,NaT,pd.NA, and infinite numbers becomenull, timestamps ISO 8601 text,Decimala number (an integral one exactly, any other as a float, which can round: a NUMERIC column that needs every digit should be cast to text before it is read). A list or object result must be the whole value, as any; a DataFrame can never be the result.Errors: an empty table, no such column or row, or a
nullcell ismissing_value; a value of the wrong kind istype(is_list_emptyof a string,get_column_as_listof a number); invalid JSON forjson_parseisargument. Any other failure inside a function isargumentnaming only the exception type. Messages never include the arguments’ values. A nested table function with no value is a missing argument, socoalescegives a default for it:@{coalesce, @{get_value_from_dataframe, 0, id, tasks.read.output}, none}.A table or value function over a secret (
@{get_value_from_dataframe, 0, password, @{json_parse, @{get_secret, …}}}) returns part of it. When a secret was read for its arguments, every string in its result of 6 or more characters (after trimming blanks) is recorded as a secret, soscrubmasks it and SQL refuses it, and so refuses any later value that contains it. That includes harmless fields of the same secret, such as a user name. Shorter strings and numbers are not recorded: keep a short credential (a PIN) as its own vault key and read it whole withget_secret. Only a secret read for that call’s own arguments counts: a JSON secret first resolved into a variable and parsed by a later placeholder is not split into parts.is_emptytakes a string, array, object, or table. The otheris_*checks take only their own type (is_dataframe_empty: a DataFrame or an array of objects);nullis empty for all of them.
A service’s own functions¶
A service adds functions to its context; they are known only there.
def get_rate(base: str, quote: str = "EUR") -> float: ...
ctx = Context.from_values({**values, "fx": {"rate": "@{get_rate, NOK}"}}, functions={"get_rate": get_rate})
ctx.resolve("fx.rate") # get_rate("NOK")
validate(definition, functions={"get_rate": get_rate}) # counts checked
validate(definition, functions={"get_rate"}) # by name only
Each is called with the arguments’ values, positionally, like the table functions: a reference argument as the provider holds it,
nullor blank asNone. Its signature sets how many arguments it takes (arityotherwise). The result is converted to plain JSON;Noneor blank ismissing_value.An exception it raises becomes
argument, naming only the exception type. To report a missing value, raiseMissingValue. Anasyncfunction is refused when the context is built.It gets the provider’s own objects (a DataFrame is not copied): never change an argument in place.
A secret inside a JSON text inside a cell is escaped twice by
dataframe_to_json_array, andscruband the SQL check do not see it there. Don’t put secrets in task outputs.It must not return a secret: its result is not recorded as one (unless a secret was read for one of its arguments, see the table and value functions), so
scruband the SQL check do not know it, andresolve(strict=False)does not read it. Put secrets in the vault and read them withget_secret.A built-in name cannot be replaced, and building the context fails if one is given. A later version that adds a built-in with the same name makes that explicit: rename the service’s function then.
Every validator of the same definitions must know the same names, or they are
unknown_functionthere. Where the functions are not at hand (ds-config, the router), pass the names.
Testing with a fixed clock¶
A function given at needs nothing special. For the current time (a date
function without at, and the _now functions), use the test helper:
from ds_common_placeholder_py_lib import Context
from ds_common_placeholder_py_lib.testing import fixed_now
ctx = Context.from_values({"tenant_id": "t1", "run": {"at": "@{get_unix_timestamp_now}"}})
with fixed_now("2026-11-03T10:15:30Z"):
ctx.resolve("run.at") # 1793700930
Like fake_vault, it applies to the current thread or async task only.
Not in standard¶
get_ssm_secret (no tenant scope; move the secret to the vault and use
get_secret) and new_uuid4 (differs on every retry) stay legacy only.
Using one in a standard definition is an unknown_function error.
Adding a function is a contract change: the registry, the conformance vectors, and a version bump go together.