Every caterpillar of the current 170,000 different species of Lepidoptera has their own special food for that species. This because over 100 million years ago, when Lepidoptera evolved from their precursor insects, some fed on primitive plants. This was not good for the plants that they ate. So over the millennia, plants evolved to create internal poisons to kill any caterpillars feeding on them. Different plants evolved different metabolisms, and split into different families and different species, each making different poisons.
Meanwhile the caterpillars evolved into different families and species to cope with this problem. Some caterpillar species gave up eating plants and adapted to eating animal hair, or animal dung, or seeds, or Lichen, or other insects. But also many caterpillar species evolved to be able to metabolise the poisons without harm in the various plant families that were evolving.
This escalating war between caterpillars and plants, of defence and counter-defence, has been going on continually over the last 100 million years or so, and this has led to there now being the 400,000 species of flowering plants, and the 170,00 species of Lepidoptera, that we have in our world today, with each plant species having only a limited number of caterpillar species that can feed on it, and each caterpillar species being able to feed only on those plants or other things that it has adapted to feed on.
(written 13 March 2020, updated 24 September 2020)