Parametrize a pipeline
Pass values to a pipeline when a run starts, and the same code serves different runs. Typical values are the dates or hours to process, a tenant or a region, a setting such as a threshold or a number of results, or a secret such as an API key. Models read a parameter either as $name in SQL and filters, or as a function argument; see use them in filters and as arguments.
Declare the parameters
Declare every parameter in the project file, under parameters, with a type (str, int, float, bool or secret), an optional default and an optional required flag.
Declare dates as strings. Parameters have no date type. Declare dates and timestamps as str in ISO format.
parameters:
start_date:
type: str
default: "2026-09-01"
end_date:
type: str
default: "2026-09-02"
Give every parameter a default, or mark it required. With a default, a run started without arguments, such as a development run, still works. A required parameter stops the run before it starts if it's missing. A parameter with neither is passed to the model as None. top_n has no default, and is required:
parameters:
top_n:
type: int
required: true
Use them in filters and as arguments
A parameter reaches a model in a filter, or as an argument of the function. The examples read a table of order lines and return one row per product and day.
In a filter
Write $name in the filter of an input. Bauplan replaces it with the run's value before it reads the table:
def top_products(
lines: Annotated[
pa.Table,
bauplan.Model(
"sales.order_lines",
projection_schema=OrderLines,
filter="order_date >= $start_date AND order_date < $end_date", # Parameters used to filter input data
),
],
...
) -> Annotated[pa.Table, TopProducts]:
...
Build filters with $name, not by editing the string. Filters are read from the source before the run and must be string literals. A parameter is the only way to change a filter between runs without changing the code.
Compare the column as is, without casting it. The SQL engine casts the string to the type of the column. order_date >= $start_date compares dates, and created_at >= $start_date compares timestamps.
In overwrite_filter
Use the same parameters in overwrite_filter. Each run then rewrites exactly the window it read:
@bauplan.model(
materialization_strategy="OVERWRITE_PARTITIONS",
partitioned_by=["order_date"],
overwrite_filter="order_date >= $start_date AND order_date < $end_date", # Parameters used to overwrite partitions
)
@bauplan.python("3.13")
def top_products(...) -> Annotated[pa.Table, TopProducts]:
...
See overwrite a window of partitions.
As a function argument
Add an argument annotated with bauplan.Parameter("<name>"). The function receives the value as an ordinary Python variable:
def top_products(
lines: Annotated[pa.Table, bauplan.Model("sales.order_lines", ...)],
top_n: Annotated[int, bauplan.Parameter("top_n")], # Parameters used as input to the function, usable as standard Python variables
) -> Annotated[pa.Table, TopProducts]:
"""Rank products by revenue within each day, and keep the first top_n."""
import polars as pl
return (
pl.DataFrame(lines)
.group_by("order_date", "product_id")
.agg(pl.col("amount").sum().alias("revenue"))
.filter(pl.col("revenue").rank("ordinal", descending=True).over("order_date") <= top_n)
.to_arrow()
)
Here the body uses it to keep the first top_n products of each day.
Pass values when the run starts
Pass the required parameters, and override any defaults, when the run starts. From the CLI:
bauplan run --param start_date=2026-09-01 --param end_date=2026-09-02 --param top_n=10
From the SDK:
client.run(
project_dir="<project_dir>",
ref=branch,
parameters={"start_date": "2026-09-01", "end_date": "2026-09-02", "top_n": 10},
)
Every parameter you pass must be declared.
Store secrets
If a model needs a secret, such as an API key, store it encrypted in the project file. Set it with the CLI, which encrypts it with your organization's key:
bauplan parameter set crm_api_key '<value>' --type secret --required
The model receives the decrypted value as a string argument, like any other parameter.
Set the secret again in every project that needs it. The encrypted value is bound to the project ID, and can't be copied into another project.