11-28-2025 07:49 AM
Hi, apologies if this is a daft question - I'm relatively new to Databricks and still finding my feet!
I have a notebook with a parameter set within it via a widget, like this:
dbutils.widgets.dropdown("My widget", "A", ["A", "B", "C"])
my_variable = dbutils.widgets.get("My widget")
As you can see, the only options available to pick are 'A', 'B', and 'C'.I want to run this notebook through a job, so I can log runs. I want to set the value of my_variable through a job or task parameter in the job.
I know how to create a job or task parameter, and that the value this is set to can be picked up by widgets.get. However, I don't know how I can restrict the values that can be entered to 'A', 'B', and 'C'; there doesn't seem to be an option to do this.
Does anyone know how to do this please?
12-01-2025 11:17 AM
Job/task parameters are free-form strings (or JSON) that get pushed down into tasks; there’s no built‑in way in Jobs to constrain them to an enum list like A/B/C in the UI or API. You can override them at run time, but they’re not validated against the widget choices.
val = dbutils.widgets.get("My widget")
# Validate against your curated list
allowed = {"A", "B", "C"}
if val not in allowed:
# Fail fast (or coerce to a default) so job runs are clearly logged as invalid
raise ValueError(
f"Invalid value for 'My widget': {val}. Allowed values are {sorted(allowed)}."
)
11-28-2025 08:42 AM
Databricks Job/Task parameter interface does not provide a built-in UI feature to restrict the possible values entered by user. Yoou can add a runtime validation code inside the notebook to allow/fail based on the values entered in.
11-30-2025 09:11 PM - edited 11-30-2025 09:12 PM
Hi @SRJDB ,
Here is a work around, you can switch to the widget to text parameter and implement a enums. It helps in validation in both value as well as case check. Using enums in one of the best practices to use constant variables. More over you can add functions that can terminate the notebook gracefully if you have mentioned wrong values.
You can use the below command to terminate the notebook,
dbutils.notebook.exit("Optional exit value or message")
12-01-2025 11:17 AM
Job/task parameters are free-form strings (or JSON) that get pushed down into tasks; there’s no built‑in way in Jobs to constrain them to an enum list like A/B/C in the UI or API. You can override them at run time, but they’re not validated against the widget choices.
val = dbutils.widgets.get("My widget")
# Validate against your curated list
allowed = {"A", "B", "C"}
if val not in allowed:
# Fail fast (or coerce to a default) so job runs are clearly logged as invalid
raise ValueError(
f"Invalid value for 'My widget': {val}. Allowed values are {sorted(allowed)}."
)