Detection and mitigation of misbehaviour in LLMs