You can use
- assert
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/assert_module.html - or fail
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/fail_module.html
It will go along with something like this
#check if params are invalid then abort below all tasks.
- name: 'check parm is null or invalid'
fail: msg="Please enter correct Params"
when: "param1 is not defined or param2 is not defined " ## whatever condition you want