When I fight widow spiders, they tend to use beguile on my ranged units but my archers and mages always hit their intended target (never their allies). if beguile isn't supposed to work on ranged units, then the AI shouldn't use them on ranged units, unless it's one of the mistakes the AI should make (I play on challenging).