Slightly bitter potatoes or onion I have got the same annoying result a few times now, when making potato gratin, and something known as "french potato cake" in my country (grated potato in frying pan). 

I believe that it's the potato which has a slightly off taste; bitter/metallic/raw. Some googling leads to solanine as an explanation, but I'm not completely satisfied.

Things that might be related:


I rarely peel them (yet, I think that the same batch of potatoes, used a few days apart did taste fine the first time).
I think that it's worse when any piece of potato isn't in direct contact with heat (i e the center of a thick potato cake or gratin)
I almost always add raw, finely grated onions.
Sometimes raw garlic - my impression is that it makes it worse.
The potatoes are not green, at all, in any of these circumstances.


So my guesses are:


Solanine, in that case solution is to peel them? 
Something related to oxidation, either in garlic/onion or perhaps catalysed by it. Solution, in that case?
Rawness - can potatoes be soft and still be "raw"?
My gut tells me that they are either under-done or need to be rinsed. Have you tried par boiling the  potato? I would try slicing the raw potato, boiling for a few minutes to draw out some of the starch - then rinsing them before adding to your recipe. Worth a try I think.

Good luck!