Let $(X, \mu)$ be a measurable space. The Cauchy-Schwarz inequality tells us that if $f \in L^2(X)$, then $|\int_X f \bar g\, d\mu|$ is bounded as $g$ ranges over the elements of $L^2(X)$ with norm $1$.
I was wondering if the following partial converse holds
Let $f$ be a complex-valued measurable function on $X$. Suppose that for all $g \in L^2(X)$ with norm $1$, the inequality $|\int_X f \bar g \, d\mu| \leq 1$ holds. Then $f$ is square integrable. (i.e. $f \in L^2(X)$)
TrialAndError's hint above was all I needed. We can define a linear functional by $x^*(g) = \int_X g \bar f \, d\mu$. The condition the gives that $x^*$ is bounded since $\|x^*(g)\| \leq \|g\|$ for all $g \in L^2(x)$. By the Riesz representation theorem, there is $f_0 \in L^2(X)$ such that
$$\int_X g \bar{f_0} \, d\mu =x^*(g) = \int_X g \bar f \, d\mu$$
So we obtain that for any $g \in L^2(X)$, $\int_X g \overline{(f_0 - f)} \, d\mu = 0$. This is enough to conclude that $f=f_0$ a.e. in the case where $X$ is $\sigma$-finite at least, which is enough for my needs.