Cayenne pepper is a good repellent to keep moles out of a yard for a limited time. Other good temporary repellents include castor oil and blood meal. While cayenne pepper is effective, it usually requires multiple applications.
Since cayenne pepper is not a permanent solution, mole traps are more effective in the long term. The best way to keep moles out of the yard is to physically remove them. Live mole traps don't harm the animals, but allow the user to get them out of the yard and into another location. Poison is not recommended since it can be a danger to other animals in the vicinity.