How to write this in less possible code?

Right, but if you’re calling String.to_existing_atom/1 on user input you still want to check if it’s a valid value, otherwise you’ll get an exception instead of being able to fall back to a valid behavior.