I eat low carb (keto). Recently I had vanilla yogurt (22g carbs) substituted for Greek yogurt (5g carbs), which I basically can't eat. There's a handful of other things where the carbs can vary wildly between brands such as sausages, salad dressing, and BBQ sauce. Not to mention that many people think the "low fat" version of anything is basically interchangeable (reality: less fat, but 10x the carbs (sugar) to make up for it).
My kid is allergic to peanuts. There's a shocking amount of things that "may contain peanuts or tree nuts" including things you wouldn't necessarily expect like pita breads, meatballs and chicken fingers. We stick to the same brands generally, but always read the label whenever buying something new.
Food allergies are probably possible to handle (though you really do have to check everything), but I don't realistically expect the pickers to follow the more specific/crazy diet restrictions. We've only done online pickup a handful of times but have stopped allowing substitutions on most things for the above reasons.
If they want to make it easier, they can give me the list of items they would consider as substitutes, and allow me to add/remove items. And they can remember the choices I've made in the past.
Right now it seems to be pretty capricious and up to the whims of someone who is in a hurry and whose primary responsibility is pulling things from shelves.
They could use software to make educated guesses. Random ideas:
(1a) Allow customers to rate substitutions after the fact as bad, OK, or good. Then learn which substitutions customers generally like, and try to do those. The goal should probably be to avoid bad substitutions, so 10% bad / 60% OK / 30% good is preferable to 25% bad / 25% OK / 50% good.
(1b) If I myself rated a substitution as bad in the past and you need to substitute for that same item again, try something different.
(2) Look for safe choices in order history. If vanilla yogurt isn't available today, but blueberry and coconut are, and in the past I've bought cherry and blueberry yogurt several times but never coconut, then give me blueberry.
(3) Get fancier and try to model features of products that a customer does and doesn't like. You've got metadata like keywords from product names, ingredient lists, brands, packaging type, and size. I bought this ice cream, those bagels, that coffee creamer, and that applesauce, and cinnamon is the common thread in all four. So when you're out of brown sugar oatmeal, give me cinnamon spice even though I've never bought that before because it looks like I like cinnamon.
(4) Model based on similarity to other buyers. I often buy these 5 items, and someone else also buys those same 5 items, but they often buy a 6th one that I don't. So maybe I'd like that 6th product too as a substitute (provided it's already on the short list of reasonable substitutes).