That's what sideboarding is for. You either know what sort of stuff they're running (you've played against it before), you know the environment you're playing in (eg Kaladesh block and Mirrodin block were both superladen with artifacts), or you're including it to exploit your own stuff. Yeah, it can be sucky to be sitting with a "dead hand", but that's a) part of the learning curve about building decks b) entirely statistically possible.