Mould is one of the most common food contaminants.
Not all types of mould are bad for you if eaten, there are several examples of good mould like the one you find in some cheeses. Having said that, you should have good mould in your starter!
How do I know if it's bad mould?
Mould is usually fuzzy/furry looking. The lactic acid bacteria naturally deter mould growth, which makes it very hard for mould to grow in a starter and therefore very unlikely to develop.
If you still think you have mould in your starter, then that could be for two reasons, either the starter has been standing in two high temperature for too long or poor hygiene when handling your starter. Like a dirty jar, or dirty hands/ spoons in your starter.
Mould takes a long time to grow, so for a starter to go bad, it usually means it's been neglected for a long time. So to prevent this from happening you should maintain your sourdough culture regularly.
Some tips for prevention your starter going bad.
After each feeding, clean the outside of the walls of the jar clean with a paper towel. Contamination can happen in the walls where there are some old starter left.
Feed your starter regularly, at least once per week if you have it stored in room temperature, if you have it in your fridge feed it at least every 2-3 weeks.
Just keep good hygiene by keeping the jar clean and mould or bad bacteria won't trouble you. Love your starter and show that love by feeding it regularly.