How do your players or characters know when to flee? Are you using only published monsters? It might be a carry over from Rolemaster, but in most of my games, the power of the monsters are not know to the players until they have fought them more than once and even then there are different power levels for the same monsters. Specially if the DM is using home brew versions of any of the monsters.
At my table, anything more powerful than it looks has a reputation. So (e.g.) an armored troll mercenary with 11 levels of Fighter is an infamous threat, and the PCs are likely to hear word of it long before they might encounter it.
(Note that since I run a sandbox, there is no conservation of detail: the PCs hear about the reputations of a lot of more unique foes than they end up encountering. I don't expect my players to have perfect memory or notes, so if they forget a particular bit of rumor they've already heard I will remind them.)
The most dangerous threats at my table tend to be high-level NPCs of the PC races, and there is plenty of rumor and gossip about them. If the PCs plan on confronting the archmage of one of the big mage guilds, it's pretty simple to find other mages willing to gossip about what spells the archmage is known for casting, and that can give the PCs insight into the archmage's approximate level. (I use the option in the DMG to build NPCs using PC rules, so knowing that the archmage (e.g.) routinely casts
Project Image to attend nearby meetings lets the players accurately infer that the she's at least 13th level, and quite probably higher. Of course, it also lets the PCs know that since she casually uses high level spells for mundane purposes, with careful timing they may be able to catch her depleted in spell slots.)
For secretive foes, or foes that have moved into the area from far away, there will be less immediately available information from local rumor. This can be simply addressed by letting the PCs see the newcomer in combat against a third party. But it's also ok to leave an occasional foe with unknown capabilities: if the PCs are used to having intel, the lack of such intel will stand out, tipping off the PCs that active research would be a good idea prior to any confrontation. (Examples include using networking and
Sending to try to find a contact of a contact who knows more about this foe, spells like
Legend Lore, or even good old-fashioned scrying and mundane spying.)
Of course, all of these methods depend on a PC-driven campaign style, where encounters are drvien by the PCs' informed choices. At my table kicking down a door when you don't already know what is (or could be) on the other side is extremely dangerous, particularly at lower levels. (At higher levels the odds of randomly running into anything powerful enough to be a threat are low, and methods for escape are more reliable.)
I'm probably making it sound like my campaigns are mostly research and planning, but that isn't how it ends up. Inferring the potential range of opponents can often be simple and indirect. For example, when trying to eradicate a thieves guild, knowing that they, in aggregate, steal only a couple hundred GP-worth a year puts a pretty hard cap on how threatening (and rewarding!) their guildhouse is likely to be, because they won't be able to afford to hire or retain a large crew or anyone truly scary, nor are they likely to have much cash on hand. And the level of aggregate thefts can be inferred from the local merchants' willingness/eagerness to fund a reward. Sure, sometimes such inferences can be incorrect (maybe the guildmaster is an independently wealthy master thief who runs this crew just to stave off boredom during retirement) but foreshadowing the exceptions is straightforward.