We are given that \( \sin \theta = \frac{a}{b} \), where \( b \) is the hypotenuse and \( a \) is the side opposite to the angle \( \theta \). To find \( \cos \theta \), we can use the Pythagorean identity:
\[
\sin^2 \theta + \cos^2 \theta = 1.
\]
Substitute \( \sin \theta = \frac{a}{b} \) into the identity:
\[
\left( \frac{a}{b} \right)^2 + \cos^2 \theta = 1 \quad \Rightarrow \quad \frac{a^2}{b^2} + \cos^2 \theta = 1.
\]
Solving for \( \cos^2 \theta \):
\[
\cos^2 \theta = 1 - \frac{a^2}{b^2} = \frac{b^2 - a^2}{b^2}.
\]
Thus, \( \cos \theta = \frac{\sqrt{b^2 - a^2}}{b} \).
Therefore, the value of \( \cos \theta \) is \( \boxed{\frac{\sqrt{b^2 - a^2}}{b}} \).