I don't think this is really related to them being erratic. What makes erratic AIs special is that they have a small chance to randomly declare war on someone every turn, and that's not what's giving you trouble. AIs will attack someone when they're boxed in, even "pacifistic" ones. It's like a law of nature. Once the borders solidify, the classic MOO1 undeclared border wars happen, and buttering up the AIs with diplomacy will not protect you, but it does prevent them from going into total war mode. You can sign a NAP which will give you an advance warning when they go after you, and makes it slightly more likely that they pick another target, if available. Signing an alliance makes it vastly more likely (again: only if another target is available), but that's going to take a long time. Also, don't sign the NAP too early because it removes your ability to blockade unclaimed planets!
Otherwise, see if you can build something to counter whatever the enemy is fielding and do back up your claim.
My general rules for erratic AIs are not to offer large trade deals (unless you're the Humans). Small trade deals to improve relations are still good. Avoid trading them techs that you don't want used against you. That's actually a good rule for all AIs
I wish I knew what to do about alliance cheese (which isn't specific to erratic AIs either). I've lost to this in every Imperium I attempted. Keep checking reports to know who's allied and at war with whom. If you can, have good relations with your neighbors so you can convince them to break alliances. Rapid expansion in the early game helps too, of course.