Shouldn't this be in the
BG section?
Anyway, in
pnp, the best defense against
imprisonment is to not get on the bad side of any being capable of using such magic. Failing that, don't allow said being to finish casting it, or just make sure it does not get the opportunity to touch you.
In
pnp imprisonment has a range of touch and demiliches do not have such an imprisonment ability. They just used the spell to duplicate the
trap the soul power of the demi-lich, which is far more potent than
imprisonment.
Others have mentioned typical strategies for
BG that work. One thing that I've done is to simply send a bunch of summoned monsters in first and let them get imprisoned, suplimenting that with some party members, if needed.