Beans and lentils are not grains, so from that point of view they are safe.  However, peanuts and soybeans (along with dairy) can mimic gluten in the intestines (causing hyperpermeability – leaky gut) and should be avoided.  Beans also contain lectins which bother some people.  It's all a question of what you can tolerate!