                     FACT T EST: Factuality Testing in Large Language Models with Statistical Guarantees

(qi , M (qi )) in D, we define an indicator variable yi ∈ {0, 1}        The threshold is then set to: τ̂α = T(k̂) . Note that τ̂α is
to indicate the correctness of M (qi ) such that                        well defined for any n0 , ensuring Type I error control ir-
          (                                                             respective of the calibration sample size n. Specifically,
             1, if M (qi ) aligns with the true answer ai ,             when n0 is small such that v(n0 ) > δ, the threshold be-
     yi =
             0, otherwise.                                              comes τ̂α = T(n0 +1) = +∞, causing fˆα to conservatively
Based on these indicators, the dataset is divided into:                 classify all pairs (q, M (q)) as incorrect, thereby abstaining
                                                                        from answering any question. The derivation is deferred to
      D1 = {(qi , M (qi )) ∈ Q × A : yi = 1, i ∈ [n]},                  Appendix. A.
      D0 = {(qi , M (qi )) ∈ Q × A : yi = 0, i ∈ [n]}.
Note that the construction of the indicator vari-                       Theorem 2.1. For any n ∈ N+ , with probability at least
able y = I(M (q) aligns with a) for (q, M (q), a) ∼                     1 − δ, the constructed classifier fˆα has type I error below
Pq,M (q),a defines a distribution Pq,M (q),a,y , then the data          α, i.e.,
{(qi , M (qi ), yi )}ni=1 are i.i.d. samples from Pq,M (q),y over          PD P(q,M (q))∼P (fˆα (q, M (q)) = 1) ≤ α ≥ 1 − δ.
                                                                                                                       
                                                                                             0
all possible combinations of (q, M (q), y), and the distri-
butions of D0 and D1 are P0 = Pq,M (q)|y=0 and P1 =
Pq,M (q)|y=1 , respectively.                                            With the determined threshold τ̂α , the predictor
                                                                        fˆα (q, M (q)) = I(η̂(q, M (q)) > τ̂α ) is formally de-
Correctness Predictor based on Score Function. Suppose                  fined. This classifier ensures that, for a given significance
there is a score function η̂ : Q × A → R that measures                  level α, the Type I error is controlled below α with high
the correctness of (q, M (q)). The value is expected to be              probability 1 − δ. Consequently, when η̂(q, M (q)) ≥ τ̂α ,
large if M has the ability to provide a factual answer. The             we reject the null hypothesis H0 and assert that the model
predictor fˆα (q, M (q)) can then be defined as:                        M can answer the question q correctly. Otherwise, the
                                                                        model will output an acknowledgment of uncertainty.
            fˆα (q, M (q)) = I(η̂(q, M (q)) > τ̂α )          (2)
                                                                        2.3. Type II Error Control
where I is the indicator function and τ̂α is a threshold to be          The effectiveness of FACT T EST not only hinges on Type I
determined. The task thus reduces to selecting a threshold              error control but also on ensuring sufficient statistical power
τ̂α that satisfies the requirement in Eq. 1:                            to detect true positives. We then analyze the Type II error
                                                                        of the constructed classifier, which is the probability of
      PD (P(q,M (q))∼P0 (η̂(q, M (q)) > τ̂α ) > α) ≤ δ.      (3)        misclassifying correct (q, M (q)) from P1 as incorrect.
                                                                        Denote η(q, M (q)) = Py∼Py|q,M (q) (y = 1|q, M (q)) to be
Calibration and Threshold Selection To determine the ap-                the conditional probability that M (q) aligns with the correct
propriate threshold τ̂α , we utilize the calibration subset D0 .        answer a given any question q and the generated answer
                                                   (0)    (0)
Denote the n0 samples in D0 by D0 = {(qi , M (qi )) :                   M (q). Note that a question q may have multiple correct
                                                 (0)    (0)
i ∈ [n0 ]}. For each calibration sample (qi , M (qi )) ∈                answers and a is just one realization from Pa|q . Therefore, a,
                                         (0)       (0)
D0 , we compute the score Ti = η̂(qi , M (qi )). We then                and thus y, may still be random given (q, M (q)), implying
order these scores in ascending order to obtain the order               η(q, M (q)) may take value in (0, 1). For any classifier
statistics T(1) ≤ . . . ≤ T(n0 ) , and set T(n0 +1) = +∞. Mo-           f , we set R0 (f ) = P(q,M (q))∼P0 (f (q, M (q)) = 1) (resp.
tivated by the seminal works (Vovk, 2012) on the PAC-style              R1 (f ) = P(q,M (q))∼P1 (f (q, M (q)) = 0)) to be the Type I
conformal prediction and (Tong et al., 2018) on Neyman-                 error (resp. Type II error). It follows from Theorem 1 in
Pearson classification, if we set the threshold τ̂α to be the           (Tong, 2013) that the Bayes optimal classifier fα∗
kth smallest score T(k) , the probability for fˆα to have type I              fα∗ ∈     arg min      R1 (f )   s.t.   R0 (f ) ≤ α
error greater than α can be controlled in a distribution-free                         f :Q×A→{0,1}

and finite-sample manner,                                               has the form fα∗ (q, M (q)) = I(η(q, M (q)) > τα ) for some
                                                                        τα ∈ [0, 1]. Therefore, fα∗ is the optimal rule for detecting
                                                                        incorrect answers and η is an optimal choice of the score
   PD (P(q,M (q))∼P0 (η̂(q, M (q)) > T(k) ) > α)
    n0  
                                                                        function.
   X     n0                    △                    (4)
 ≤            (1 − α)j αn0 −j = v(k), k ∈ [n0 + 1],                     Suppose there exist an increasing function H and ϵη > 0
         j
    j=k                                                                 such that ∥H ◦ η̂ − η∥∞ ≤ ϵη , where H ◦ η̂(q, M (q)) =
when k = n0 +1, v(k) is defined to be 0. We then determine              H(η̂(q, M (q))) is the composition of H and η̂. Let py =
k̂ as                                                                   Py∼Py (y = 1) denote the marginal probability that M is
          k̂ = min{k ∈ [n0 + 1] : v(k) ≤ δ},           (5)              correct. We define:

                                                                    3
