When under attack by more troops than you can handle, or one of the top alliances, either use a Peace Shield, or use up as many resources you can (to minimise how much they can loot) and send your troops out to gather at the Alliance Farm/Sawmill/Mine or far away tiles, or reinforce an ally who has an active peace shield garrison them at the Alliance Fortress (though be ready to call them back if the fortress gets attacked).
Your troops are only safe inside a stronghold that has an active Peace Shield, or at the Alliance Resource Building (Alliance Farm/Sawmill/Mine)
Before attacking an enemy city, or their troops, check if they are part of an alliance, and whether that alliance is larger than you and your alliance can handle, or allied with your alliance. Also check the whiteboard at the Great Hall to verify that the entire Kingdom doesn't have a kingdom-wide peace treaty.
It's recommended to avoid attacking top players or alliances.
Don't attack alliances listed in your Alliance Feed or Alliance Motto as Family or Allies or NAP (Non Aggression Pact).