There's no definitive way to avoid any hand like this. Someone flops a weird straight, a set, a low 2 pair against your top pair top kicker - what can you do? Same as in any hand: you bet reasonably hard for information. If you seem to be getting smooth-called or even raised, you have to seriously consider the possibility that your hand is beaten, and let it go.

Top pair top kicker will make you a lot of money as a rule, but it's far from impregnable. Analyze the board and the pre-flop betting. A lot of people like to limp pocket pairs, so if they were as passive as possible pre-flop and all the sudden are calling you down or raising you post-flop, you could be in trouble.