As a DM you are expected to have a certain amount of material prepared for a gaming session. Preparations include plot, NPCs, and potentially combat, but what happens when things don't go in the direction you expected? Some DMs would choose to make almost a world border to keep players on track (not my favorite thing to do, but it's sometimes needed), but in theory it shouldn't be an issue if your party strays away from the expected path. Inevitably the party will come up with things that you didn't plan for and you really can't prepare for it. However, your party doesn't need to know that.
Baccob's Blessed Blog brought up what he calls the DM's "Oh Sh!t Sheet" which is basically a sheet where you have NPC names, encounters, traps, and rewards all setup in case your party steps off the predicted trail. This sheet will provide enough info for you to roll with the punches and hopefully your party will never notice the difference. While it is useful to have names, encounters, traps, and treasures on one sheet, realistically you can customize it to what you need. Perhaps you're well-versed in coming up with names on the fly, but you tend to trip up on characteristics, then generate out some that you can easily roll for. Partly as a way to make NPC interactions more realistic, I found myself creating a set of character generation tables based on regions in Faerun. So with a few rolls I can create NPCs with different skills and dispositions in a town so when a player asks if there is a magic shop in town, I can roll up a character to see if there is and ultimately if there is that character may be helpful or non. While I don't have the full sheet on hand the table was something like this:
Race |
Human | 01-40 |
Dwarf | 41-55 |
Half-Elf | 56-70 |
Halfling | 71-80 |
Half-Orc | 81-87 |
Elf | 88-95 |
Gnome | 96-00 |
Occupation |
Merchant | 01-30 |
Blacksmith | 31-40 |
Tavern Worker | 41-50 |
Hunter/Fisher | 51-60 |
Guard | 61-70 |
Clergy | 71-80 |
Commoner | 81-95 |
Royalty | 96-00 |
Merchant Type |
Common Goods | 01-40 |
Weapons/Armor | 41-60 |
Magic/Enchantment | 61-80 |
Potions | 81-00 |
Demeanor/Attitude |
Hostile | 01-15 |
Unfriendly | 16-30 |
Indifferent | 31-70 |
Friendly | 71-90 |
Helpful | 91-00 |
Regardless of what you put on your "Oh Sh!t Sheet" be sure that you are at least slightly prepared for things to go off track. This doesn't always mean you need this sheet, in some cases it will be better to direct the party back to the plot at hand, but it can't hurt to have your sheet ready so NPCs can direct the party back to the plot rather than setting up barriers that prevent characters from steering away from the conflict.