Practically speaking, sometimes taking a deep breath before you speak gives you the extra second or two for your brain to catch up with your mouth.
Also, try really
listening to what the other person is saying...90% of the time we're not really listening, we're thinking about what we want to say and looking for an opportunity to look good/smart/funny. If you try really focusing on the other person's thoughts and words your brain might just put the kneejerk comments on the back burner.
Another good practice in support of both of these strategies is
mindfulness meditation, even for just 5 minutes a day.