You're right, you can definitely get yourself in trouble if you don't take a few precautions. Don't purchase from dirty vendors that seem like they just don't put enough care into sanitation of their product. Look for busy vendors that seem to have a lot of local clientele, this usually means that the food is good if the locals eat it. Also watch the spice levels, as you can find yourself visiting a lot of toilets if you eat the wrong spices!
You're right, you can definitely get yourself in trouble if you don't take a few precautions. Don't purchase from dirty vendors that seem like they just don't put enough care into sanitation of their product. Look for busy vendors that seem to have a lot of local clientele, this usually means that the food is good if the locals eat it. Also watch the spice levels, as you can find yourself visiting a lot of toilets if you eat the wrong spices!