Hello,
The simplest solution would be to remove the validation rule you have set, that is blocking the process (probably something like "required", add "permit_empty" instead). Then do the validation yourself like you are doing already in your function.
As I see it, this is not really a "validation" if the provided data is always "valid". It seems to be more like a "filter" function.