Back in the olden days, when I was writing The Green Lion Trilogy, there was a scene where one of my two MCs was asked a question, which could have gotten him in trouble regardless of whether he answered it "Yes" or "No." He gave a rather slick (I thought at the time) response that evaded the trap. I snickered to myself as I wrote it.
But revising the scene much later it occurred to me that no matter how much I, personally, enjoyed that line, it was completely out of character for him to even think about evading the blame. He was the super-responsible sort who took too much on himself and who'd be more likely to blurt out something along the lines of "Everything that happened was all my fault!"
On the other hand, he wasn't at fault, and if he had been in trouble at that point it wouldn't have worked for what had to happen next in terms of the plot. So, as I recall, I had one of the other characters who had been present step in before he could speak, and exonerate him.
But it was an important learning experience for me, because I realized, perhaps for the first time, that far more important than writing clever dialogue it was my job to consider the personalities of all the characters and never put words in their mouths that didn't match their thought processes and motivations. After that, whenever I wrote some dialogue that I particularly enjoyed writing, asking myself the question, "But would they really say that? helped keep me honest.