The answer to this question involves a lot of factors that may vary from organism to organism, but can broadly be divided into two categories: innate and learned.
Innate factors include the way an organism is structured and how its body is designed. The majority of ant-eating creatures have specialized mouthparts that allow them to extract nutritious substances from ant larvae, pupae and adults. Some gastropods (snails) are able to digest the exoskeletons of ants, extracting all the available nutrients from these hard shells. In comparison, the jaws and stomachs of most vertebrates are not adapted for chewing hard substances, which is why almost all vertebrates avoid eating ants. Some invertebrates, such as some butterflies and moths, are able to digest cellulose in wood so they can extract food usable by their larvae. However, because ants do not process cellulose in this way they are avoided by these predators too.
Learned factors include how