# 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: `lookup, [.]` | `@{lookup, owner.settings.company_key}` | | Function call: `` or `, , …` | `@{get_start_date_last_month, Europe/Oslo, run.logical_at}` | - A namespace is any name of `A-Z`, `a-z`, `0-9`, and `_` that starts with a letter or `_`. A path segment is `A-Z`, `a-z`, `0-9`, `_`, `-`, and `:`, so UUIDs and names like `READ::POSTGRESQL` work 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 function `owner`, not a namespace: read the whole namespace with `@{lookup, owner}`. The docs write every reference with [`lookup`](functions.md#lookup). 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.name` | A 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.5` | Any other bare text: always a string (`2026` is `"2026"`) | | `'report.csv'` | The text `report.csv`. **Quote any text that looks like `name.path`** (file names, host names such as `s3.eu-west-1.amazonaws.com` or `localhost.x:8080`, versions such as `v1.2-beta`): unquoted, `report.csv` is a reference to a namespace `report`, which `validate` cannot catch and which fails at resolution | - Whitespace 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). ## 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. ```text @{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}` are `syntax`. It cannot be the function name (`@{@{x}}`) or a part of a path (`@{owner.@{x}}`), and `lookup`'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, `null` or blank, a function that returned nothing, or a table function that found no value (an empty table, no such row or column, a `null` cell). `coalesce` moves 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 with `missing_value`, except that the table and value functions get `null` for a value that is `null` or blank or a nested call that returned nothing, as for a reference; a missing path is `missing_value` there too. - Every other error is raised, inside `coalesce` too: 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 `syntax` error. ## 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: ```python 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`): ```python 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 `validate` reports 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 raises `ValueError`. - 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](sql.md)): 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`: ```python 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 | | --- | --- | | `"@{'@{not a placeholder}'}"` | `"@{not a placeholder}"` | | `"a@{'@{'}b"` | `"a@{b"` | | `"@{str_join, '@{x}'}"` | `"@{x}"` | | `"user@@{lookup, owner.domain}"` | `"user@"` + the domain: `@` before a placeholder is just text | | `"app:@{get_secret, …}@@{lookup, owner.host}/db"` | password, `@`, host | {py:func}`~ds_common_placeholder_py_lib.grammar.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](#verbatim-fields) 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 `@{.…}` 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 | | --- | --- | --- | | `tenant_id` | The run's tenant, a string; fixed and always taken as written | The context itself (`Context.from_values` requires it) | | `owner` | The owner record (`id`, `name`, `type`, `settings`) | The stage request's `context.owner`: a pipeline job runs for one owner, and the router forwards its record to every stage dispatcher | | `variables` | The run's variables, as written; resolved when read (see below) | The service, from the definition and the request | | `run` | Facts fixed when the run was created: `job_id`, `tenant_id`, `pipeline_id`, `trigger_type`, `triggered_at`, `logical_at`, `load_mode` | The request | | `execution` | This execution: `id`, `name`, `attempt_no`, `started_at` | The request, and the service for `started_at` | | `tasks` | Outputs of earlier workflow tasks, `{task_id: {"output": …}}`, growing during the run | 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: `` is the first row's value, `rows` the rows as objects, and `rows.` 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 | `"@{x}"` | `"id-@{x}"` | | --- | --- | --- | | `"643b"` | `"643b"` | `"id-643b"` | | `1234` | `1234` | `"id-1234"` | | `2.0` | `2.0` | `"id-2.0"` | | `true` | `true` | `"id-true"` | | `["a"]` | `["a"]` | `type` error | | `{"a": 1}` | `{"a": 1}` | `type` error | ## 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`](functions.md#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): ```json "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](services.md#variables)): ```python 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 {py:class}`~ds_common_placeholder_py_lib.context.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 with `cycle`. - its `verbatim` and `sql` paths: values that are data, taken as written, and values that are SQL text. For values a service computes itself, pass an object with `get(path)` that returns the value or raises {py:class}`~ds_common_placeholder_py_lib.errors.MissingValue` (a {py:class}`~ds_common_placeholder_py_lib.context.Provider`). - the tenant id, which `get_secret` keys must name. - the secrets read, for `scrub` and for refusing secrets in SQL. Resolved values stay in memory (§10). Do not write them to events, rows, logs, or checkpoints.