<@ULVA73B9P> How do I make parameters required in ...
# ask-marvin
k
@Marvin How do I make parameters required in a flow associated with a deployment?
m
To make parameters required in a Prefect flow and associate them with a deployment: 1. Update your flow to include parameter validation logic, ensuring required parameters are specified before the flow can run. There is no built-in feature for 'required parameters' in Prefect Core as parameters default to
None
if not explicitly set. You would have to check for parameter existence at the beginning of your flow run with custom validation logic. 2. When defining the deployment, you can specify a
parameter_openapi_schema
to enforce a particular schema for parameters used in flow runs. To ensure that the Prefect API checks the parameter values against the provided schema, set
enforce_parameter_schema
to
true
in your deployment configuration. For ad-hoc runs with different parameter values: - Go to the details page for a deployment. - Select "Run", then "Custom". - You will be able to provide custom values for any editable deployment fields. - Under Parameters, select "Custom". - Provide the new values and then select "Save". - Select "Run" to begin the flow run with custom values. Find more information in the Prefect documentation here. Please be aware that when you set
enforce_parameter_schema
to
true
, all future flow runs based on that deployment will require the parameter values to pass the schema validation, thus effectively making some parameters required.
n
hmm a much simpler answer here is just that its based on your flow function's signature
Copy code
@flow
def foo(required: str, not_required: str | None = None):
   pass

if __name__ == "__main__":
   foo.serve(__file__)