2. The function
$$
f(x)=\sqrt{3} \sin ^{2} x+\sin x \cdot \cos x-\frac{\sqrt{3}}{2}\left(x \in\left[\frac{\pi}{12}, \frac{\pi}{2}\right]\right)
$$

has the range . $\qquad$
2. $\left[-\frac{1}{2}, 1\right]$.

From the problem, we have
$$
\begin{array}{l}
f(x)=\sqrt{3} \times \frac{1-\cos 2 x}{2}+\frac{1}{2} \sin 2 x-\frac{\sqrt{3}}{2} \\
=\frac{1}{2} \sin 2 x-\frac{\sqrt{3}}{2} \cos 2 x=\sin \left(2 x-\frac{\pi}{3}\right) .
\end{array}
$$

Since $x \in\left[\frac{\pi}{12}, \frac{\pi}{2}\right]$, we have
$$
\begin{array}{l}
-\frac{\pi}{6} \leqslant 2 x-\frac{\pi}{3} \leqslant \frac{2 \pi}{3} \\
\Rightarrow-\frac{1}{2} \leqslant \sin \left(2 x-\frac{\pi}{3}\right) \leqslant 1 .
\end{array}
$$