Skip to content
AgenticAIWiki
  1. Learn
  2. Part 1
  3. 7. Hallucination and grounding
  4. 7.3

Lesson 7.3 · 3 of 4 · 4 min read · Reviewed 24 Nov 2026

Letting the model say "I don't know"

By the end, you can

  • Give the model permission to say 'I don't know'.
  • Design answers for uncertainty.

Why permission matters

Training rewards helpful answers, so without guidance a model leans toward answering. Saying explicitly that “I don’t know” is acceptable, and what to do next, changes that.

A prompt pattern

If the documents don't contain the answer:
- Say: "I couldn't find that in our help articles."
- Say what you'd need, if anything (for example an order number).
- Offer to connect the user with support.
Don't guess, and don't use outside knowledge for policy questions.

Good uncertainty

Situation Good response
Answer not in sources Say so; suggest next step
Question ambiguous Ask one clarifying question
Partly answerable Answer the part you can; flag the rest
Low confidence Give the answer with the reason for doubt, or escalate

Structured uncertainty

In structured outputsStructured outputs: Making a model return data that matches a defined schema, such as JSON with required fields and types., give the model a valid way to express “unknown”: nullable fields (chapter 14), an “insufficient_information” label, or a confidence field you check against evalsEval: A repeatable test that measures how well an AI system performs on a set of cases with defined success criteria..

Test it

Include unanswerable questions in your test set (chapter 26). A system that answers 100% of questions probably invents some answers.

Key points

  • Models tend to answer something; explicitly allowing 'I don't know' reduces guessing.
  • Define what to do instead: ask a clarifying question, say what's missing, or hand off.
  • Test it with questions that have no answer in the sources.
Hands-on labRuns in the Playground

Add an honest not-found path

Make a toy assistant say 'not in the docs' when retrieval finds nothing good, and measure how often it gets that call right.

You will have: A retrieval threshold, a fallback reply and a score for answered and refused questions on a six-question test set.

Steps

  1. Run the starter: the assistant answers every question, including ones the docs don't cover.
  2. Score each question against the docs by shared key words and keep the best match.
  3. If the best score is below the threshold, reply with the not-found message and a next step.
  4. Run the test set and count correct answers and correct refusals.
  5. Try thresholds 0.2, 0.4 and 0.6 and pick the one with the most correct outcomes.

Done when

  • At the chosen threshold, both unanswerable questions get the not-found reply.
  • All four answerable questions are answered.
  • The script prints 'best threshold: 0.4 (6/6 correct)'.

Open in the Playground No API key needed.

Starter code (Python)
import re
DOCS = {
    "returns": "Unworn items can be returned within 30 days of delivery.",
    "shipping": "Standard shipping takes 3 to 5 working days.",
    "warranty": "Laptops have a two year warranty against faults.",
}
TESTS = [  # (question, should it be answered?)
    ("How many days do I have to return unworn items?", True), ("How long does standard shipping take?", True),
    ("What warranty do laptops have?", True), ("Can I return items after delivery?", True),
    ("What is the CEO's phone number?", False), ("Do you sell gift wrapping for laptops?", False),
]
NOT_FOUND = "I couldn't find that in our help articles. I can connect you with support."

def words(t):
    return {w for w in re.findall(r"[a-z]+", t.lower()) if len(w) > 3}

def best_match(q):
    scores = {k: len(words(q) & words(v)) / max(1, len(words(q))) for k, v in DOCS.items()}
    k = max(sorted(scores), key=scores.get)
    return k, scores[k]

def reply(q, threshold):
    doc, score = best_match(q)
    # TODO: return NOT_FOUND when score < threshold
    return DOCS[doc]

def evaluate(threshold):
    return sum((reply(q, threshold) != NOT_FOUND) == should for q, should in TESTS)

print("correct at 0.4:", evaluate(0.4), "of", len(TESTS))
# TODO: try 0.2, 0.4 and 0.6 and print the best threshold
Show a solution
import re
DOCS = {
    "returns": "Unworn items can be returned within 30 days of delivery.",
    "shipping": "Standard shipping takes 3 to 5 working days.",
    "warranty": "Laptops have a two year warranty against faults.",
}
TESTS = [
    ("How many days do I have to return unworn items?", True), ("How long does standard shipping take?", True),
    ("What warranty do laptops have?", True), ("Can I return items after delivery?", True),
    ("What is the CEO's phone number?", False), ("Do you sell gift wrapping for laptops?", False),
]
NOT_FOUND = "I couldn't find that in our help articles. I can connect you with support."

def words(t):
    return {w for w in re.findall(r"[a-z]+", t.lower()) if len(w) > 3}

def best_match(q):
    scores = {k: len(words(q) & words(v)) / max(1, len(words(q))) for k, v in DOCS.items()}
    k = max(sorted(scores), key=scores.get)
    return k, scores[k]

def reply(q, threshold):
    doc, score = best_match(q)
    return NOT_FOUND if score < threshold else DOCS[doc]

def evaluate(threshold):
    return sum((reply(q, threshold) != NOT_FOUND) == should for q, should in TESTS)

results = {t: evaluate(t) for t in [0.2, 0.4, 0.6]}
for t, r in results.items():
    print(f"threshold {t}: {r}/{len(TESTS)} correct")
best = max(results, key=lambda t: (results[t], -t))
print(f"best threshold: {best} ({results[best]}/{len(TESTS)} correct)")
for q, _ in TESTS[4:]:
    print(q, "->", reply(q, best))
Quick checkYour assistant invents answers when the knowledge base lacks the information. What prompt change helps most?
How sure are you?
Pick an answer and how sure you are