How do I write a formal resignation letter to my toxic PI advisor
It can be extremely short and to the point. You don't need to give your reasons:


  For personal and professional reasons I've decided to resign my position in your lab. 


Nothing more is required as long as your contract, if any, permits it at all. In particular don't say things that might be disputed by others.