2. Point $P(a, b)$ is in the first quadrant, and a line $l$ is drawn through point $P$, intersecting the positive $x$ and $y$ axes at points $A$ and $B$ respectively. Then, when $P A^{2}+P B^{2}$ takes the minimum value, the slope of line $l$ is $\qquad$ .
2. $-\frac{\sqrt{a b}}{a}$.

As shown in Figure 5, construct $P C \perp x$-axis at $C$, and $P D \perp y$-axis at $D$, then $P D=a, P C=b$.
Let $\frac{P B}{P A}=\lambda \quad(\lambda>0)$.
From $\triangle P A C \backsim \triangle B P D$, we get
$$
\frac{P B}{P A}=\frac{B D}{P C}=\frac{P D}{A C}=\lambda \text {. }
$$

Therefore, $B D=\lambda P C=\lambda b$.
Thus, $P B=\sqrt{B D^{2}+P D^{2}}=\sqrt{\lambda^{2} b^{2}+a^{2}}$.
Also, $P A=\frac{1}{\lambda} P B$, so
$$
\begin{array}{l}
P A^{2}+P B^{2}=\frac{1}{\lambda^{2}} P B^{2}+P B^{2}=a^{2}+b^{2}+\frac{a^{2}}{\lambda^{2}}+\lambda^{2} b^{2} \\
\geqslant a^{2}+b^{2}+2 a b=(a+b)^{2} .
\end{array}
$$

When and only when $\frac{a}{\lambda}=\lambda b$, i.e., $\lambda=\frac{\sqrt{a b}}{b}$, $P A^{2}+P B^{2}$ reaches its minimum value. At this time, the slope $k$ of $l$ is $k=-\frac{B D}{P D}=-\frac{\lambda b}{a}=-\frac{\sqrt{a b}}{a}$.
Figure 5