Problem: If $f(x)=\frac{1}{x^2+1}$ and $g(x)=\sqrt{x}$, then what is the derivative of $f(g(x))$?
My book says the answer is $-(x+1)^{-2}$. This answer seems flawed because $(\sqrt{x})^2$ is being simplified to $x$ when it should really be simplified to $|x|$. If $(\sqrt{x})^2$ is simplified to $|x|$ then the answer I get is instead $-\frac{x}{|x|(|x|+1)^2}$. But the book is probably right so is there something I'm overlooking?
$$(\sqrt{x})^2\ne|x|.$$
Don't confuse $\left(\sqrt{x}\right)^2$ and $\sqrt{x^2}$. They actually give you different results:
$$\left(\sqrt{x}\right)^2=x,\ x\ge0$$
and
$$\sqrt{x^2}=|x|.$$
Plug these functions into an online graphing utility such as Desmos and you will see that $f(x)=\left(\sqrt{x}\right)^2$ has graphical output only for $x\ge0$. That's because the square root function is not defined for negative values of $x$. $f(x)=\sqrt{x^2}$, on the other hand, is nothing more than your good old absolute value function. It's defined on the entire real line.
So, the answer to your problem should really be: $$ -\frac{1}{(x+1)^2},\ x\ge0. $$
It should be $x\ge0$ because the original function is simply not defined for values of $x$ that are less than zero and therefore evaluating the derivative at those values would not make sense. However, they did not write $x\ge0$ next to their answer. That's because that information is already there as part of the original function which is a result of the composition of two other functions: $$\left(\frac{1}{\left(\sqrt{x}\right)^2+1}\right)'=-\frac{1}{(x+1)^2}.$$
See that square root function? It tells you that the domain of this new function is only those $x$ values that are greater than or equal to zero.
More properly, your original function should actually be written like this:
$$f(g(x))=\frac{1}{\left(\sqrt{x}\right)^2+1}=\frac{1}{x+1},\ \ x\ge0.$$
And that's the function you're talking the derivative of.