Do tell. It's impossible to know what you're claiming without some details. The AI tends to get hostile if you're too close; it can randomly get triggered into hostility by chain-reaction relationship issues, or because "you're trying to win the game the same way I am." They declare war if you're getting too far ahead in a "peaceful" metric.
Granted, if you have no neighbors they're incompetent at doing anything to you - is that what you mean?
1. Don't conquer other civs or city-states, even in "self-defense" or because some other civ asks you to. Seems obvious, but based on the griping here about being treated as a warmonger for "only" razing half the planet, it has to be said.
2. Keep your word. If you promise Babylon not to settle near his lands, don't settle near his lands.
3. Keep a strong, up-to-date military as a deterrent to aggressive or bullying civs. Keep up with your city fortifications, too. You never want to be the easiest target.
4. Pick your Declarations of Friendship carefully. In the late game, it's often best to avoid them as the diplomatic situation can change rapidly and you can find yourself "friends" with the new enemy of a suddenly truculent neighbor.
5. Bribe AIs into wars with each other to keep them occupied / knock down their military forces to parity or below with your own, making you a less attractive target. Not randomly, of course, but strategically - if Mongolia's getting grouchy with you, a war with France might be just the thing to redirect his attention.
6. Rescue and return stolen workers or settlers from barbs. Especially in the early game, obviously, when there are more of them around. You get a ton of positive feeling from this.
Of course, if you're alone on a small continent or archipelago, it's a lot easier than on a pangaea map.
But I've had success with this approach on larger land masses, too, though I haven't played at the highest difficulties yet.
Now, it's possible to follow all of this advice to the letter and still find yourself in a war. There are just too many variables, between geography, resource distribution, proximity to other civs, and the individual personality of each AI, for any single strategy to be an iron-clad, foolproof, can't-lose-no-matter-what guarantee of a peaceful victory. But if there was such a thing, what would be the point of playing?