Sub topic 7
Parameterizing jobs and tasks
This chapter assumes you can write a Databricks notebook in Python or SQL, and that you have already built a job with two or more tasks. It covers job parameters, task parameters, and how a notebook reads them.
Why parameterize
A job that hard-codes a date, a table name, or an environment is hard to reuse. Parameters let you run the same job for a different day, test it against a dev schema, or backfill one customer, without editing the notebooks.
Job parameters and task parameters
A job parameter is a key-value pair defined on the job itself. Every task can read it. A task parameter is defined on one task and applies only to that task.
For notebook tasks, both kinds arrive in the notebook as widgets. A widget is a named input field that a notebook reads with dbutils.widgets.get.
You can reference a job parameter in a task parameter with a dynamic value reference. The syntax is {{job.parameters.<name>}}. Databricks also provides other references, such as {{job.id}}, {{job.run_id}} and {{task.name}}.
{
"name": "daily-sales-pipeline",
"parameters": [
{"name": "run_date", "default": "2026-01-01"},
{"name": "env", "default": "dev"}
],
"tasks": [
{
"task_key": "ingest",
"notebook_task": {
"notebook_path": "/Workspace/Shared/ingest",
"base_parameters": {
"source_schema": "{{job.parameters.env}}_raw"
}
}
}
]
}In this definition, run_date and env are job parameters. The source_schema task parameter is built from env. A run started with env=prod passes prod_raw to the notebook.
Reading parameters in a notebook
dbutils.widgets.text("run_date", "2026-01-01")
dbutils.widgets.text("source_schema", "dev_raw")
run_date = dbutils.widgets.get("run_date")
source_schema = dbutils.widgets.get("source_schema")
df = spark.table(f"{source_schema}.orders").where(f"order_date = '{run_date}'")
print(f"Loaded {df.count()} rows for {run_date}")The dbutils.widgets.text calls declare the widgets and give them defaults. When the notebook runs as a job task, the job's values replace those defaults. When you run it by hand, the defaults apply.
How values are resolved
A run can override a job parameter. You can do this with "Run now with different parameters" in the UI, or by passing job_parameters to the run-now API. Scheduled runs use the defaults.
Common errors
- Parameter name mismatch. A widget named
runDatewill not receive a parameter namedrun_date. Names are case-sensitive. - Everything is a string.
dbutils.widgets.getalways returns text. Convert withint()ordatetime.date.fromisoformat()before doing arithmetic. - Unsafe SQL strings. Building SQL with f-strings is fine for trusted table names. Avoid it for free-form user input, because a value can change the query.
- Hard-coded defaults in production. If a scheduled run relies on a stale default date, it quietly reprocesses old data. Use
{{job.start_time.iso_date}}where you want the run's own date.
Exercise
A job has the parameter env with default dev. A task passes "target": "{{job.parameters.env}}_gold". You start a manual run with env=prod. What does the notebook receive for target, and what type is it?
Show answer
It receives the string prod_gold. Widget values are always strings, and the override replaces the default before the dynamic reference is resolved.