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

                                                                        3.2. Type I Error Control under Covariate Shift

              τα (1 − py )
                                     r
                                       α     1                          To extend the procedure in Section 2 to the covariate shift
                                ′
       ξα =                ,   α =α−c     log ,                         setting, we take an additional step to transform the sam-
              (1 − τα )py              n0    δ
                                                                        ples in D0 from P̃0 to P0 distributed random variables by
        ϵτ = τα′ − τα + ϵη ,                                            rejection sampling.
                                                                        In the first step, we generate n0 uniform random vari-
for some constant c > 0. If we denote Gα (ϵ) =                                                 i.i.d.
                                                                        ables U1 , . . . , Un0 ∼ Unif[0, B] and select the indexes
P(q,M (q))∼P0 (|η(q, M (q)) − τα | ≤ ϵ) to be the probabil-                                           (0)    (0)
                                                                        I = {i ∈ [n0 ] : Ui ≤ w(qi , M (qi ))}. If we collect
ity measure around the classification boundary of fα∗ , then
                                                                        all the samples in D0 with indexes in I to form D̃0 =
the following theorem states that as long as the score func-               (0)       (0)               △
tion η̂ measures the level of correctness of M , the type II            {(qi , M (qi )) : i ∈ I} = {(q̃i , M (q̃i )) : i ∈ [ñ0 ]}.
error of our algorithm is small.                                        Then it will be shown in Appendix A that given the selec-
                                                                        tion I by rejection sampling, the selected samples D̃0 follow
Theorem 2.2. If η̂(q, M (q)) is a continuous random vari-                                                       i.i.d.
                                                                        the target distribution P0 i.e., D̃0 | I ∼ P0 .
able with (q, M (q)) ∼ P0 , α ≳ logn1/δ
                                    0
                                        and τα +ϵτ +ϵη < 1,
then with probability at least 1 − 2δ, we have                          In the second step, we apply the procedure introduced in
                                                                        Section 2 to the incorrect subset D̃0 . Specifically, given
  R1 (fˆα ) − R1 (fα∗ )                                                 the incorrect subset D̃0 , we calculate the scores T̃i =
     r
        α      1        (1 − py )(ϵτ + ϵη )                             η̂(q̃i , M (q̃i )) and order them in increasing order to get
 ≲ξα        log +                            Gα (ϵτ + ϵη ).             T̃(1) ≤ . . . ≤ T̃(ñ0 ) , and set T̃(ñ0 +1) = +∞. Then we
        n0     δ     py (1 − τα − ϵτ − ϵη )2
                                                                        set the threshold τ̂α to be T̃(k̂) , with k̂ satisfies
3. Extension of FACT T EST to Covariate Shifts                             k̂ = min{k ∈ [ñ0 + 1] : ṽ(k) ≤ δ},
The threshold selection procedure developed in Section                             ñ0  
                                                                                   X    ñ0
2 relies on the assumption that the calibration dataset                    ṽ(k) =           (1 − α)j αñ0 −j , ṽ(ñ0 + 1) = 0.
                                                                                         j
D0 = {(qi , M (qi )) ∈ Q | yi = 0} follows the target                               j=k
distribution P0 of incorrect question-generated answer pairs.                         i.i.d.
However, labeled samples from the target distribution may               Since D̃0 | I ∼ P0 , theoretical results in Section 2 can be
not always be available in practice. Instead, people may use            directly applied here. Due to limited space, we control the
the labeled data that they believe to be similar to the target          Type I error as follows.
distribution, which necessitates methods to handle distribu-            Theorem 3.1. With probability at least 1−δ, the constructed
tion shifts. In this section, we study the case of covariate            classifier fˆα (q, M (q)) = I(η̂(q, M (q)) > T̃(k̂) ) has type I
shift, where the distribution of the question-generated an-             error below α, i.e.
swer pairs in the calibration data differs from that in the                PD (P(q,M (q))∼P (fˆα (q, M (q)) = 1) ≤ α) ≥ 1 − δ.
                                                                                               0
target distribution, while the conditional distribution of y
given (q, M (q)) remains the same.
                                                                        4. Connection with Conformal Prediction
3.1. Setup
                                                                        In Sec. 2, we formulate our method within the NP classifica-
Suppose we observe n samples D = {(qi , M (qi ), yi ) : i ∈             tion framework by defining an NP classifier for error control.
[n]} from the source distribution P̃q,M (q),y . We assume               In this section, we explore the inherent relationship between
Py|q,M (q) = P̃y|q,M (q) but Pq,M (q) ̸= P̃q,M (q) , i.e., the          NP classification (Tong et al., 2018) and PAC-style confor-
distribution of questions changes but the oracle rule of de-            mal prediction (Vovk, 2012), demonstrating that FACT T EST
tecting incorrect answers remains. Following Section 2, we              can also be formulated within the lens of conformal pre-
split D into a correct subset D1 = {(qi , M (qi )) : yi =               diction. To the best of our knowledge, this work presents
                      (1)         (1)                                   the first formal articulation of the connection between NP
1, i ∈ [n]} = {(qi , M (qi )) : i ∈ [n1 ]} and an in-
correct subset D0 = {(qi , M (qi )) : yi = 0, i ∈ [n]} =                classification and PAC-style conformal prediction.
    (0)      (0)
{(qi , M (qi )) : i ∈ [n0 ]}. We denote the distribution of             Challenges of conventional conformal prediction. Recent
D0 , D1 to be P̃0 , P̃1 , respectively. We further denote the           works applying conformal prediction to LLMs (Kumar et al.,
density ratio between the target distribution P0 of incorrect           2023; Quach et al., 2024; Li et al., 2024) have primarily
question-generated answer pair and the source distribution              focused on answer set coverage guarantee. A naive appli-
P̃0 to be w(q, M (q)) = dP      0
                             dP̃0
                                  (q, M (q)). In this section, we       cation of prediction sets to hallucination detection might
assume w is known and satisfies w(q, M (q)) ≤ B for all                 involve verifying whether outputs fall within the prediction
(q, M (q)) ∈ Q × A.                                                     set. However, this approach is fundamentally flawed for

                                                                    4
