I would must be followed by an infinitive without to ( or perfect infinitive as in I would have gone). I had must be followed either by an object (a noun phrase, e.g. I had a little lamb, in which meaning it is rarely contracted) or by a verb's past participle. So it's (almost) always possible to distinguish between them by analyzing the words that follow.
I'd go. (go = infinitive => 'd = would)
I'd had. (had = participle => 'd = had)
The only ambiguous case is when the verb's infinitive coincides with its participle.
I'd put. (could be would or had)
But these cases are rare and the meaning can be deduced if more context is provided