Self-Check is a pattern where the LLM evaluates its own output for correctness, safety, or policy compliance before returning it. The model generates an answer, then a second pass critiques that answer against specific criteria, and the system either accepts, revises, or rejects the response.
At a Glance
- Problem: Language models state false claims, such as invented citations or dosages, as fluently and confidently as true ones. Where users act on factual output and no ground-truth database is available, you need a way to flag answers the model is unsure about.
- Forces: Detection quality versus inference cost and latency, since consistency checks multiply both; aggressive thresholds that catch more hallucinations versus flagging correct outputs and losing user trust; one threshold for everything versus the labeled data needed for domain calibration.
- Solution: Read the model's own confidence signals: token logprobs, sequence perplexity, agreement across several sampled generations, or a second pass that critiques the answer. Outputs that fall below a threshold are flagged, revised, or rejected.
- Consequences: Gains: a detection layer for uncertain claims, nearly free when the API already returns logprobs. Costs: sampling and critique passes add cost and latency, thresholds need labeled data to calibrate, and confident mistakes pass undetected, so the pattern flags some hallucinations but cannot prevent them.
What problem does Self-Check solve?
Language models sound confident even when they are wrong. They do not pause, hedge, or signal uncertainty the way a human expert would. A model asked about a court case will invent a plausible-sounding citation with the correct formatting, a realistic case number, and a made-up ruling. A model asked about a medication will produce a coherent paragraph with fabricated dosage information. The output reads well, and it is false.
Do not expect the next model version to fix this, because it follows from how these systems work. Language models predict the next token from statistical patterns. They have no fact-checking step and no database of verified information to consult. When the training data is sparse on a topic, the model fills the gaps with plausible completions that are fluent, grammatical, and sometimes dangerous.
For applications where factual accuracy matters, like legal research, medical information, financial analysis, or any domain where wrong answers have consequences, you need the model to check itself and flag the outputs it is uncertain about.
How does Self-Check work?
The self-check pattern relies on the fact that language models do expose their internal confidence, even if they do not express it in their text output. Most model APIs can return log probabilities (logprobs) for each generated token. These numbers tell you how likely the model considered each token before selecting it. A high probability means the model was fairly certain. A low probability means it was choosing among many plausible alternatives, and that is where hallucinations tend to occur.
The simplest approach is to monitor logprobs on the tokens that matter most. In a structured output where the model produces key-value pairs, you often care about the values more than the keys. If the model generates "capital: Nairobi" with high confidence on "Nairobi" but generates "population: 4,397,073" with low confidence on the numeric tokens, that second fact deserves scrutiny. You can set a threshold and flag any claim where the relevant tokens fall below it.
A more reliable method is to generate the same response multiple times (using a non-zero temperature) and compare the outputs. If the model produces consistent answers across five generations, it is likely drawing on well-represented training data. If each generation gives a different answer, the model is guessing. This consistency check does not require access to logprobs at all, which makes it work with APIs that do not expose them.
You can also compute perplexity over a generated sequence as a normalized confidence metric. Perplexity aggregates token-level probabilities into a single number that represents how "surprised" the model was by its own output. Lower perplexity means higher confidence. Sequences with unusually high perplexity relative to your application's baseline are candidates for human review or rejection.
For production systems, some teams train a lightweight classifier on top of token probability features. You collect examples of verified correct outputs and known hallucinations, extract their probability profiles, and train a small model to distinguish between them. This gives you a fast, automated hallucination detector tuned to your specific domain.
When should you use Self-Check?
Self-check is most valuable when your application generates factual claims that users might act on. If the model is writing creative fiction or brainstorming ideas, invented content is what you asked for. If the model is producing legal summaries, medical recommendations, or financial reports, you need confidence scoring.
This pattern also makes sense when you cannot verify outputs against a ground-truth database in real time. If you have a database to check against, do that instead. Self-check is for situations where the facts are too varied, too subtle, or too numerous for lookup validation.
It is worth building once you have the engineering capacity to handle flagged outputs. Self-check tells you something might be wrong. You still need a plan for what happens next. That might mean routing to a human reviewer, falling back to a retrieval-based answer, or telling the user that the system is not confident in this particular response.
When not to use it: Do not rely on Self-Check as the only safeguard for high-stakes outputs, because confident mistakes pass undetected; ground the answer with Grounded Generation and add Human-in-the-Loop review. Skip multi-generation consistency checks on high-throughput, latency-sensitive paths where sampling several times is unaffordable, and fall back to logprob checks or asynchronous scoring. And when the concern is policy violations or leaked private data rather than uncertain facts, Guardrails is the right layer.
Implementation
The example below shows the critique variant of Self-Check: a second call checks the first answer against its sources and returns a verdict. It works with any model. The token-probability variant described above needs an API that returns logprobs, and flags low-confidence spans instead of asking for a verdict.
# Using OpenAI SDK for illustration — swap client for any provider
import re
from openai import OpenAI
client = OpenAI()
def self_check(question: str, context: str = "") -> dict:
"""Generate a response, then verify it for accuracy."""
# Step 1: Generate the initial response
gen_messages = [{"role": "user", "content": question}]
if context:
gen_messages.insert(0, {"role": "system", "content": f"Answer based on this context:\n{context}"})
response = client.chat.completions.create(
model="gpt-4o", messages=gen_messages,
)
answer = response.choices[0].message.content
# Step 2: Ask the model to verify its own claims
verification = client.chat.completions.create(
model="gpt-4o",
messages=[{
"role": "user",
"content": f"""Review this answer for accuracy. List any claims that might be wrong or unverifiable.
Question: {question}
Answer: {answer}
Reply in this format:
VERDICT: PASS or FAIL
ISSUES: (list any problems, or "none")""",
}],
)
check_result = verification.choices[0].message.content
return {
"answer": answer,
"verification": check_result,
"passed": re.search(r"^VERDICT:\s*PASS\b", check_result, re.I | re.M) is not None,
}
# Usage
result = self_check("What year was Python first released?")
print(f"Answer: {result['answer']}")
print(f"Passed: {result['passed']}")
Worked Example: Cost and Latency
A legal research assistant answers 5,000 questions a day with the large model, using 1,500 input tokens and 400 output tokens per answer.
| Setup | Calls per request | Tokens per request (in / out) | Cost per 1,000 requests | Latency per request |
|---|---|---|---|---|
| Single generation, no check | 1 | 1,500 / 400 | $10.50 | 7.2 s |
| Logprob check | 1 | 1,500 / 400 | $10.50 | 7.2 s |
| Five-sample consistency on every request | 5 | 7,500 / 2,000 | $52.50 | 7.2 s parallel, 35.8 s sequential |
| Logprobs first, five samples on the 15% flagged | 1 (5 if flagged) | 1,500 / 400 (7,500 / 2,000 if flagged) | $16.80 | 7.2 s, 14.3 s if flagged, 8.2 s average |
One answer costs 1,500 × $3.00 per million + 400 × $15.00 per million = $0.0105 and takes 0.5 s + 400 / 60 s ≈ 7.2 s. Logprobs come back with the same call, so they add nothing. Five samples cost five times as much and, run one after another, take five times as long. In the hybrid, 15% of answers (an assumed flag rate) get four more samples run in parallel after the first: $10.50 × (1 + 0.15 × 4) = $16.80 per 1,000, and flagged answers take two rounds, about 14.3 s.
Logprob monitoring is free and worth leaving on; consistency sampling on every request adds about $0.04 per question, which pays only where a wrong answer costs far more than that, and gating it behind logprobs keeps most of the coverage at a fraction of the price.
What are the common pitfalls?
Logprob thresholds are not universal. A probability that indicates high confidence on one topic might indicate low confidence on another. Rare but correct tokens (unusual proper nouns, technical terminology) will have lower probabilities even when the model is right. You need domain-specific calibration, and that takes labeled data.
The multi-generation consistency check is expensive. Generating five responses instead of one multiplies your inference cost by five and your latency by roughly the same factor unless you can run generations in parallel. For high-throughput applications, this cost may be prohibitive for every request. A common compromise is to run consistency checks only on outputs that the logprob analysis flags as uncertain.
Self-check can make a system look safer than it is. High confidence does not guarantee correctness. Models can be confidently wrong, especially on topics that are well-represented in training data but where the training data itself contains errors. Self-check catches uncertainty. It does not catch confident mistakes.
There is also the risk of over-filtering. If your thresholds are too aggressive, you will flag correct outputs as potentially hallucinated, undermining user trust and reducing the utility of the system. Calibrating thresholds requires ongoing monitoring with real production data.
What are the trade-offs?
Cost increases with the sophistication of your self-check approach. Logprob monitoring is nearly free if the API already returns probabilities. Multi-generation consistency checks multiply your costs linearly. Training a custom classifier requires labeled data collection and model maintenance.
Latency is the other major cost. Any self-check that requires additional model calls adds time. For conversational applications where users expect sub-second responses, you may need to run checks asynchronously and surface confidence indicators after the initial response.
Self-check does not fix hallucination. It detects it, sometimes. You are adding a probabilistic detection layer on top of a probabilistic generation system. The combination is better than generation alone, but it is not a guarantee. Critical applications should combine self-check with retrieval-based grounding and human review for high-stakes outputs.
Goes Well With
Guardrails provide the enforcement mechanism that self-check needs. Self-check identifies uncertain outputs. Guardrails in the output layer can act on that information, blocking, flagging, or modifying responses that fail confidence thresholds.
Grounded Generation complements self-check by requiring the model to cite its sources. Self-check tells you whether the model was confident. Source citation tells you where the information supposedly came from. Together, they give both quantitative and qualitative signals about output reliability.
LLM-as-Judge extends self-check by using a separate model to evaluate the quality and accuracy of outputs. While self-check analyzes the generating model's own confidence signals, LLM-as-Judge provides an independent second opinion. The two approaches catch different categories of errors.
References
- Manakul, P., Liusie, A., & Gales, M. J. F. (2023). SelfCheckGPT: Zero-Resource Black-Box Hallucination Detection for Generative Large Language Models. EMNLP 2023. arXiv