I was sued while at my previous department (along with the boss, the mayor, the zoning enforcement officer, and I think a couple of other town officials). The lawsuit was ultimately dismissed before it even went to trial, largely because I had documented everything with code sections and the plaintiff's case largely consisted of "Yeah, but I'm spayshul, I shouldn't have to follow those silly codes they're yammering about." Plus, pre-COVID we had a joint annual, all-day training seminar presented by the chief prosecutor for code enforcement matters from the state attorney's office, and every year she hammered into us that, "If you don't have a citation, you don't have a violation."
I haven't been named in any lawsuits at the current department, but the department and the current boss have. It's not fun. The boss loses a lot of sleep due to worries about the lawsuit, and I lost a lot of sleep over the one in which I was named.