RAG · Lesson 42 of 120
Saying I Don't Know
When the facts are missing.
Sometimes the answer just isn't in our documents. A good RAG system says so, instead of making something up. An honest I don't know is far better than a confident wrong answer.

- Answer not in documents
- Don't make it up
- Say I don't know
The rule in our prompt
Our prompt in llm dot py has two rules. Answer using only the context. And if the answer isn't there, say I don't know. That second line gives the model a safe way out.
llm.pypython
PROMPT = """Answer the question using only the context below.
If the answer is not in the context, say "I don't know".
Context:
{context}
Question: {question}"""Asking about something we lack
We ask three questions. Northwind doesn't sell skateboards, so the help centre never mentions them. Run it. The skateboard question gets I don't know, and the other two get real answers.
dont_know.pypython
from rag_kit import load_docs, make_chunks, Index
from llm import answer
index = Index(make_chunks(load_docs()))
for q in ["Do you sell skateboards?",
"How long is the frame warranty?",
"When is the York store open?"]:
print(q, "->", answer(q, [c for s, c in index.search(q)]))Output
Do you sell skateboards? -> I don't know How long is the frame warranty? -> Based on the context provided, all Northwind frames have a lifetime warranty for the original owner. When is the York store open? -> Based on the provided context, the York store is open Monday to Saturday, from 9am to 5:30pm, and is closed on Sunday.
Also uses rag_kit.py
import warnings; warnings.filterwarnings("ignore")
from pathlib import Path
import numpy as np
from sentence_transformers import SentenceTransformer
import faiss # after torch, so the two libraries load safely together
faiss.omp_set_num_threads(1)
from langchain_text_splitters import RecursiveCharacterTextSplitter
def load_docs(folder="data/rag/northwind"):
return [{"source": p.name, "text": p.read_text()} for p in sorted(Path(folder).glob("*.md"))]
def make_chunks(docs, size=300, overlap=50):
splitter = RecursiveCharacterTextSplitter(chunk_size=size, chunk_overlap=overlap)
return [{"source": d["source"], "text": t.replace("\n", " ")}
for d in docs for t in splitter.split_text(d["text"])]
embedder = SentenceTransformer("all-MiniLM-L6-v2", device="cpu")
def embed(texts):
return embedder.encode(texts, normalize_embeddings=True)
class Index:
def __init__(self, chunks):
self.chunks = chunks
self.vectors = embed([c["text"] for c in chunks])
def search(self, query, k=3):
scores = self.vectors @ embed([query])[0]
top = np.argsort(-scores)[:k]
return [(round(float(scores[i]), 2), self.chunks[i]) for i in top]Also uses llm.py
from langchain.chat_models import init_chat_model
llm = init_chat_model("google_genai:gemini-flash-lite-latest", temperature=0)
PROMPT = """Answer the question using only the context below.
If the answer is not in the context, say "I don't know".
Context:
{context}
Question: {question}"""
def answer(question, chunks):
context = "\n\n".join(f"[{c['source']}] {c['text']}" for c in chunks)
return llm.invoke(PROMPT.format(context=context, question=question)).text.strip()Summary
Give the model a way out. When the context doesn't hold the answer, it should say I don't know. Next, citing sources.
Key takeaways- Missing facts
- Don't guess
- I don't know
Next up: Citing Sources — which file said it