Concepts¶
Placeholders¶
A placeholder is @{, an expression, and } inside a JSON string (§3).
Every placeholder is a function call; reading a value is the lookup call:
Form |
Example |
|---|---|
Reference: |
|
Function call: |
|
A namespace is any name of
A-Z,a-z,0-9, and_that starts with a letter or_. A path segment isA-Z,a-z,0-9,_,-, and:, so UUIDs and names likeREAD::POSTGRESQLwork as keys. A key with any other character, including a dot or a space, is quoted:@{lookup, owner.settings.'company.key'},@{lookup, owner.settings."client id"}(the quote character doubled to include it). An all-digit segment indexes an array (rows.0), in every namespace.@{owner}is a call to a functionowner, not a namespace: read the whole namespace with@{lookup, owner}. The docs write every reference withlookup. The short form@{owner.x}is the same placeholder as@{lookup, owner.x}and is still accepted.An argument is a reference, a quoted literal, a bare literal, or a nested placeholder:
Argument
Value
owner.settings.tz,dataset.nameA reference: any bare
name.path@{get_hour, Europe/Oslo, run.logical_at},@{lookup, owner.settings.tz}A nested placeholder: its value, as it is
'it''s',"a, b"The text, with the quote doubled to include it. Commas and spaces are allowed
2026,Europe/Oslo,1.5Any other bare text: always a string (
2026is"2026")'report.csv'The text
report.csv. Quote any text that looks likename.path(file names, host names such ass3.eu-west-1.amazonaws.comorlocalhost.x:8080, versions such asv1.2-beta): unquoted,report.csvis a reference to a namespacereport, whichvalidatecannot catch and which fails at resolutionWhitespace around the expression and around arguments is ignored. Only space, tab, CR, and LF count as whitespace.
Placeholders nest as arguments:
@{str_join, @{owner.id}, -, @{get_hour, UTC, run.logical_at}},@{get_secret, @{lookup, owner.settings.client_key}}. See Nested placeholders.
Nested placeholders¶
An argument can be a whole placeholder. Its value is the argument, as it
is: a number stays a number, and a value holding ,, }, or @{ is still
one argument. Nothing is substituted into the text and scanned again, so
the data a placeholder reads can never change the expression around it.
@{str_join, @{get_hour, @{lookup, owner.settings.tz}, run.logical_at}, :00} "3:00"
@{get_secret, @{lookup, owner.settings.client_key}} the same as @{get_secret, owner.settings.client_key}
@{coalesce, @{str_join, owner.settings.prefix, -x}, default} "default" when the prefix is missing
A nested placeholder must be the whole argument:
@{f, a@{x}}and@{f, @{x}b}aresyntax. It cannot be the function name (@{@{x}}) or a part of a path (@{owner.@{x}}), andlookup’s path, default and format are written out, never placeholders (argument).Any placeholder can be nested: a call, a reference (
@{owner.id},@{lookup, owner, json}), or a quoted text (@{'a,b'}, the same as'a,b'). The inner one is resolved first; the outer function then gets its value as it would get a reference’s: a string where the function takes text, any JSON value for the table and value functions.A nested placeholder with no value is a missing argument. That is a missing path,
nullor blank, a function that returned nothing, or a table function that found no value (an empty table, no such row or column, anullcell).coalescemoves on to the next argument, so@{coalesce, @{get_value_from_dataframe, 0, id, tasks.read.output}, none}gives a default for a function’s result. Any other function fails withmissing_value, except that the table and value functions getnullfor a value that isnullor blank or a nested call that returned nothing, as for a reference; a missing path ismissing_valuethere too.Every other error is raised, inside
coalescetoo: an unknown namespace or a bad argument (configuration, not data).Up to 16 levels deep; deeper is
syntax.Inside quotes
@{is still text:@{str_join, '@{x}'}is"@{x}".A placeholder in an object key is a
syntaxerror.
Protected fields¶
id, name, type, and version identify a definition and its parts. The
engine reads them before anything is resolved (to build the task graph, pick
the executor, label events), so a placeholder there would never be resolved
and would stay as text. validate therefore rejects any @{ in them, even
inside a quoted text such as @{'@{'}, with protected_field. They are not parsed. If the value is an
object or array, every string and key inside it is checked the same way.
This holds at any depth outside a settings key. Everything under a
settings key, whatever its value, is exempt (including
settings.variables): there these are ordinary keys, and
{"settings": {"name": "@{lookup, owner.settings.topic}"}} is fine. Other keys
outside settings, such as a pipeline’s sql_query, stay resolvable.
The rule goes by key, not by what a service resolves. A resolved part
outside settings cannot use these four keys for placeholders either:
{"transform": {"columns": [{"name": "@{lookup, variables.col}"}]}} is rejected.
Put such values under settings, or use another key.
Pass the whole definition to validate: only it shows which keys are
outside settings. Validating just a part (validate(task["settings"]))
would treat its top-level name as protected. resolve does not check
protected fields; services resolve only the parts that take placeholders.
The four keys are the default. A service with other identity keys passes its own list:
from ds_common_placeholder_py_lib import PROTECTED, validate
validate(definition, protected=PROTECTED | {"slug"}) # add a key
validate(definition, protected={"id", "slug"}) # replace the list
validate(definition, protected=()) # no protected keys
The same rule applies to whatever keys are given: any depth, outside
settings (settings itself cannot be protected). Every validator of the
same definitions (ds-config, the router, the frontend) must use the same
list, so keep a custom one in one shared place. protected=() is for
definition types without identity keys, not a way around the error.
Verbatim fields¶
Some values are data, not definitions: a script’s code, for example, may
contain @{ as ordinary text (s.startswith("@{")), and task outputs or an
owner record hold whatever their source wrote. Which values these are
depends on the schema, so the service names them with verbatim: to
validate, from the root of the definition, and to the context, from its
root, when it is built (or per namespace with set):
validate(definition, verbatim=["tasks.0.settings.source.content"])
ctx = Context.from_values(
{"tenant_id": t, "job": definition, "owner": owner, "tasks": outputs},
verbatim=["job.tasks.0.settings.source.content", "owner", "tasks"],
)
ctx.set("execution", execution, verbatim=["name"]) # paths inside one namespace
A verbatim value is returned as written, a copy of it. It is not parsed, so nothing in it is a placeholder, a syntax error, or a secret, and
validatereports no placeholder errors in it (protected fields aside, below). If it is an object or array, everything inside it, keys included, is taken as written.A path is written like a reference, from the root of the definition or the context: keys separated by
., an array item by its index without leading zeros (tasks.0), and a key with other characters in quotes (settings.'a.b'). Or give it as a list of keys,["tasks", 0, "settings", "a.b"]: use that when a key comes from data, such as a task id. A malformed path raisesValueError.A path that is not there is ignored, so a wrong path means the value is parsed as usual, and a well-formed placeholder in the code is replaced. Test the paths a service builds.
Paths given when the context is built apply to namespaces added later with
set, and nothing is followed through a verbatim value.Every service that handles the same value (validation, dispatcher, worker) must pass the same paths, each relative to what it passes. Let the service that owns the schema provide them, for example a
code_paths(definition)the others call.Protected fields are checked inside a verbatim value as everywhere else.
Put values into code as inputs (
main(**kwargs)), not with placeholders: text spliced into code is code, as with SQL.
SQL fields¶
A value inserted into SQL text becomes SQL code, so SQL text has its own
rules (SQL): each value becomes a SQL literal, a placeholder where
no literal can stand fails with sql_position, and a secret with
sql_secret. The library cannot tell SQL from other text, so the service
names its SQL paths with sql, like verbatim:
ctx = Context.from_values(values, sql=["transform.sql_query"])
ctx.resolve("transform") # sql_query comes out as SQL, the rest as usual
A SQL path that is not listed is resolved as plain text, values spliced in as they are: list every one.
Writing @{ as text¶
@{ always starts a placeholder. To write it as text, use a quoted text as
the whole placeholder: @{'…'} resolves to the text between the quotes,
and inside quotes @{ is just text.
Input |
Result |
|---|---|
|
|
|
|
|
|
|
|
|
password, |
escape() writes any string this way:
escape("a@{b") is "a@{'@{'}b". Use it for values from outside that must
be taken literally, such as a caller’s override of a variable. An object key
cannot contain @{ at all. For a whole value that is not a template, such
as a script, use a verbatim field instead.
Resolution is a single pass: a resolved value is never scanned again, so a
value that contains @{ stays as it is.
Namespaces¶
Namespaces are not fixed. A service puts whatever namespaces it has into the
context, and @{<namespace>.…} reads them; a namespace it does not pass does
not exist there, and a reference to it fails with unknown_namespace when it
is resolved. validate cannot know which namespaces a service will pass, so
it does not check them.
The computing blocks use these:
Namespace |
Holds |
Supplied by |
|---|---|---|
|
The run’s tenant, a string; fixed and always taken as written |
The context itself ( |
|
The owner record ( |
The stage request’s |
|
The run’s variables, as written; resolved when read (see below) |
The service, from the definition and the request |
|
Facts fixed when the run was created: |
The request |
|
This execution: |
The request, and the service for |
|
Outputs of earlier workflow tasks, |
The workflow manager |
Every namespace is read the same way: a namespace is an object or an array;
an all-digit segment indexes an array (rows.0); NaN is read as null.
A pandas DataFrame inside a namespace (a task’s output) is read as
ds-workflow-manager reads one: <column> is the first row’s value, rows the rows as objects, and
rows.<n> the row at position n (not its index label). A DataFrame itself
is never a value, only an argument of the table functions; its NaN,
NaT, pd.NA, and infinite numbers are read as null. Any other name (dataset,
env, …) works the same: pass any JSON value for it and reference it
(@{lookup, payload.0.account_id} for an array, @{lookup, region} for a
string).
execution.started_at changes on every retry. Do not use it in anything
that must be the same across retries (paths, keys, checkpoints).
Value types¶
A placeholder that is the whole string keeps the value’s JSON type. A placeholder inside a longer string is rendered as text (§8.1):
Value |
|
|
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Missing values¶
null, an empty string, a blank string (ASCII whitespace only), or a path
that does not exist is a missing value (§8.2). It fails the execution with
missing_value. There is no implicit default or fallback: if a request does
not carry a field a placeholder needs, the placeholder fails. A default is
always written out, with coalesce:
@{coalesce, owner.settings.tz, Europe/Oslo}.
Variables¶
A block declares variables in settings.variables. Their values may contain
placeholders, like any other part of the definition (§6):
"variables": {
"date_from": "@{get_start_date_last_month, Europe/Oslo, run.logical_at}",
"fiscal_year": 2026
}
The package does not treat them specially. The service passes them as
written as the variables namespace, and each is resolved when a placeholder
reads it (see Using it in a service):
ctx = Context.from_values({..., "variables": definition["settings"]["variables"]})
A variable can read any namespace in the context, another variable included. A function of the current time or a secret in one is evaluated at each read.
A pipeline run may override declared variables. The router escapes every override with
escape, so an override is always taken literally:"a@{b"sent by the caller arrives as"a@{'@{'}b"and resolves to"a@{b".@{lookup, variables.cfg.region}reads a key inside an object variable.
The context¶
A Context is one
self-contained, per-run Python object. It holds the parts of the definition
a run resolves and every value their placeholders read; what a placeholder
needs and the context lacks fails, and providing it is the service’s job.
It has:
the namespace values you passed. JSON objects and arrays are walked by path, and a placeholder in a value is resolved when the value is read, so one part of the context can use another.
ctx.resolve(path)resolves one part,ctx.resolve()all of it. A value read again while it is being resolved fails withcycle.its
verbatimandsqlpaths: values that are data, taken as written, and values that are SQL text. For values a service computes itself, pass an object withget(path)that returns the value or raisesMissingValue(aProvider).the tenant id, which
get_secretkeys must name.the secrets read, for
scruband for refusing secrets in SQL.
Resolved values stay in memory (§10). Do not write them to events, rows, logs, or checkpoints.