If we have $Z\subset X$ a closed irreducible subscheme of an integral scheme $X$ (which you can take to have various further niceness properties if you want), one can take its generic point $\eta_Z$ and localize at it, to get a local ring with quotient field the quotient field of $Z$.

However, intuitively, I'd like to be able to "take a small neighborhood of $Z$" and not just of $\eta_Z$, i.e. I'd like a canonically constructed subscheme of $X$ whose "special fiber" is $Z$ and doesn't contain any points of $X$ besides the ones which specialize to points of $Z$. Certainly in general, I wouldn't expect this to be possible, so I don't expect a general functorial construction like usual localizations. But are there known cases when something like this exists?

I'm particularly interested in when $\pi:X\to S$ is a flat family or something similarly nice, and $Z$ is a section of $\pi$, so that what I'm asking for is basically like the "relative local ring of the point $Z$ over the base $S$". Then I'd also like to ask that the pullback of my "localization at $Z$" to any fiber of $\pi$ over a closed point of $S$ yields the localization of that fiber at the point where it intersects $Z$.

In this case, if $X$ is a trivial bundle over $S$, like if $X=S\times_k Y$ for some $Y$, then obviously this is possible; I'm wondering if it's possible more generally.

(I'd also appreciate an explicit counterexample to it being possible in general flat families, since I don't expect it to be possible in that generality, but find it difficult to prove it's impossible in any particular case.)