Guards in some form are in all the cities. They do a good job of keeping low level characters following the law but after a point unless the guard is full of high level NPCs it stops working so well. This can cause a problem when the high level party decides they don't care about the town laws anymore. I had until recently could never really figure out any good ways to make it matter to the players. I have found a few good answers at Bat in the Attic that Rob Conley has come up with over his many years of gaming. Now I don't want to just parrot what was said there so I am going to state the ideas then dissect it some and then see what I could do to improve it or do it differently.
First answer comes from when he ran a campaign where everyone was a part of the guards. The players had a crossbow made that did a whole lot of damage but it had a strength requirement and took a lot of rounds to reload. Of course after that the guards had that weapon.
To dissect it some you need to take into account how long combat actually tends to be because otherwise it just looks to overpowered. After all it did something like 6d4 damage. This would be too much damage if not for the fact it takes 6 rounds to reload. By the time you manage to reload it most fights will be most likely over and you will probably have been able to do more damage just attacking especially with higher level adventurers. What it does is make players rethink breaking the law in town.
I would gladly include this into a game I run because it does what it was meant to without being overpowered. What I might change is include a little more restriction on it. As is you fire it first round and drop it. Now this is alright because later you still have to reload it and it is not exactly cheap but at higher levels there may be some chance of abuse. I would add some flavor that it needed straps to hold it up and aim properly so it takes a turn to take off. This would only delay the guard a little bit but reduce the use for a player in the dungeon enough.
Next from the same campaign the players came up with the idea of a pair of sticks that when you break one the match breaks as well. This allowed the guards on patrol to call for help. It allowed guards to call for increasingly bigger forces all the way up stopping a bunch players from doing something and escaping the city before anyone even knows what happened.
This is quite a useful idea though not as much for a party of players. Unless the players split the party about all you would use it for is if you have a character scouting ahead. For the guards though it is an amazing helper. Get in trouble on patrol? Snap the stick and you don't have to send a runner for help and you get the help in half the time!
This has almost no possibility of player abuse and I love the idea. What I would change is have it so when you break the rod in different sections the matching piece breaks in the same place so that the guards can call for bigger forces quicker by breaking it in a specific place. Have the rods have some colored bands on it to segregate the different areas to break at.
The final thing that I take from Rob is to include the player into the setting. He writes a few times how he includes the player into his world and this is the one thing that with players that want to play that stops players from bashing on your cities. By making the world important to them you let them get absorbed into the game. The high level party won't knock over the city not because its over run with even higher level NPCs but because they like that one shopkeeper they chat with every time they get back from the dungeon. They don't raze the city because their family lives there. They don't fire off fireballs at random because their contact that has given them some nice leads might get killed. When the players care about the world they play like they actually live there.
This is about the only way to make it so when the guards come that the party won't just start slaughtering. Making overpowered guards just makes the players dislike your towns. If the players respect your guards though you need to respect them. Don't force them into situations that makes them break the law then get mad at them for not coming quietly.
The include the players into the game world will only work if you really build the world well. It will work best in a setting that you plan to keep playing in just like Rob has been using Majestic Wilderlands. After all if you don't make what the players do matter then nothing you do will let them have fun.
To wrap up on guards. Don't make them idiots, Give them proper equipment, and let them communicate with themselves quickly. If you don't want magic sticks then maybe consider including some flying humanoids in the guard to alert others quicker. If giant crossbows don't do it for you just make sure they can be affective in some way. Good guard need not be high level.