They built a wall to avoid soil being washed away. - Oxford Advanced Learner's Dictionary
I think it is better to say They built a wall to prevent/stop soil from being washed away. “Prevent” is used when you want to stop something from happening, while “avoid” is used when you want to stay away from something that is already happening or existing. “Prevent” implies an active or proactive action, while “avoid” implies a passive or reactive action.
We say "avoid something" and "avoid doing something", but not "avoid someone doing something". Some people might argue that "avoid someone doing something" is valid: if you want to stay away from your friend when they are drinking alcohol, then “avoid your friend drinking alcohol” is okay. But I feel this phrase is awkward and ill-written. It's better to say “avoid your friend when they are drinking alcohol”.
Is it always better to convert "avoid someone doing something" to "avoid something", "avoid doing something" or "prevent/stop someone from doing something"?