There are two main ways of doing that:
1. Kicking any idiot in the government who is a warmonger or is stupidly taking steps that is going to lead to conflict out of office. This is specifically important for countries who are or have elected people who are not really politicians and have no clue what they are doing. Best example is Ukraine that had a celebrity as president who pushed their country into war.
2. Increasing military defensive strength to discourage any foreign force from thinking of starting any kind of conflict. That requires more budget allocation, and most importantly strategic alliances specifically with neighbors while avoiding far away players that seek their own interests at the cost of destroying your country such as what United States has been doing to other countries around the world.
Very good answer, hard to disagree !
It is only necessary to add that the first point refers to the residents of the country of the potential AGGRESSOR. And it is in their hands not to allow war to break out.
The second point is perfectly correct, and is confirmed by modern practice. The "ideal example" is Ukraine, where the pro-Russian President Yanukovych, during his term of office, did everything to extremely weaken the armed forces of Ukraine, demoralize the forces, deprive them of the necessary reserves to wage a defensive war.... The result you know - 2014, Russia's terrorist attack on Ukraine, and this terrorist war continues for the 10th year....
I would also add point 3: Joining economic and military-political alliances like NATO. Any aggressor is afraid of POWER and RESPONSE. As you know from history, there has never been a single case of a crazed aggressor attacking a country with greater military, technological, and economic potential. The peculiarity of bastard regimes is meanness and cowardice, so they attack only countries that are guaranteed to be unable to resist.