That's the approach behind Max Tegmark and Steven Omohundro's "Provably Safe AGI":
https://arxiv.org/abs/2309.01933
https://www.youtube.com/watch?v=YhMwkk6uOK8
However, there are issues. How do you even begin to formalize concepts like human well-being?