This actually touches on one area of the rules that I find frustrating and poorly executed - Sneak Attacks. IMHO, it is ridiculously easy to completely negate any chance of Sneak Attack. The defensive measures seem to fall into a few broad categories.
Concealment - Including Blur, Darkness, Fog Cloud (which even works against blindsight). Concealment completely negates any possibility of a Sneak Attack.
Uncanny Dodge - Once a character has this ability - even, say, a 4th level Barbarian - it is impossible for anyone to ever surprise the character and get a sneak attack, even an 80th level rogue.
Improved Uncanny Dodge - Prevents flanking (to an extent). Tactics can also limit flanking, so it's not as big of a deal as Uncanny Dodge.
Early detection - If you are aware of your assailants, it is harder for them to surprise you. Spells that help here include Alarm, Detect Thoughts (and most other detection spells), Glitterdust, See Invisible, Invisibility Purge, True Seeing, Foresight, and many others. Non-magical options include the Alertness feat, ranks in Spot and Listen, Improved Initiative, familiars, guard dogs (for their scent ability), animal companions, and a whole host of other options.
Barring that, just slap an Iron Body spell on every member in the party, and you're good to go.