Let's say that I have some function $f(x,y,z)$ representing an implicit surface.
For instance it might be the equation of a sphere like below, but could also be many other types of functions / shapes.
$f(x,y,z) = (x^2+y^2+z^2)^{0.5} - 0.5 = 0$
If I have a point that I know to be on the surface, what is the correct way to get a vector that is perpendicular to the surface (aka the surface normal)?
I've tried normalizing the vector made up of partial derivatives of x, y and z, but that seems to be failing for some situations.
It's difficult to provide specifics of what is failing specifically, but I'm curious, is that the correct way? or is it a problem that I really have an equation like the below with an implicit variable $w$ that I'm not taking into account in the gradient calculation?
$w=f(x,y,z)$
The unit surface normal of the implicit surface $f(x,y,z)=0$ is indeed the normalized gradient of $f$. You were also right that the unit surface normal of $z=g(x,y)$ is the normalized vector $(-g_x \ -g_y \ 1)$ (the cross product of $\mathbf{x}_u$ and $\mathbf{x}_v$, with $\mathbf{x} = (x \ y \ z)$ and $x=u$ and $y=v$).
Here is a quick proof that the unit surface normal is the normalized gradient. The function $f(x,y, g(x,y))$ is a composition of the mapping $f$ from $\mathbb{R}^3$ to $\mathbb{R}$ and the function $h$ from $\mathbb{R}^2$ to $\mathbb{R}^3$ with $h(x,y)= (x,y,g(x,y))$. The total derivative of this function using the chain rule is $$ D(f\circ h) = (Df)(Dh) = (f_x + f_zg_x \ f_y+f_zg_y). $$ Setting this derivative to zero (since $f\circ h(x,y) = 0$ is the definition of the surface) yields $g_x = -f_x/f_z$ and $g_y = -f_y/f_z$. Substituting these values of $g_x$ and $g_y$ into $(-g_x \ -g_y \ 1)$ gives $(f_x \ f_y \ f_z) / f_z,$ a multiple of the gradient.
You must have computed the partial derivatives of $f$ incorrectly, because the unit surface normal of an implicit surface $f(x,y,z)=0$ definitely is the normalized gradient of $f.$