When nothing answers the question, don’t let the model guess
Search always returns something, even when your documents say nothing. Three defences, one in the prompt, one in the output and one in your code, turn a confident wrong answer into a short wait for a person.
The 60-second version
- Search returns its closest chunks even when none of them answers the question, and a helpful model will fill the gap.
- Defence one: tell the model to answer only from the text you send, and to say so when it can’t.
- Defence two: make it return the ids of the chunks it used and a found flag, in a fixed shape.
- Defence three: check those ids in code, and hand the chat to a person when the check fails.
A customer asks, “Do you deliver to Port Blair?” Nothing in your delivery policy mentions it. Search still returns its five closest chunks, all about delivery in general, and a model that has been asked to be helpful may reply “Yes, within 7 days”, with nothing to support it.
An answer that sounds right but is not supported by any source is a hallucination. Answering only from the sources you were given is called grounding. And grounding can fail even when the right chunk is present, if the model blends your policy with what it learned in training about how other shops usually work.
Search never comes back empty. That is exactly why your system needs a way to say “I don’t know”.
Defence one: instruct
The system message should already say it plainly: use only the text inside the policy section, and if that text does not answer the question, say that a person will reply. It helps, but on its own it is a request, not a guarantee.
Defence two: ask for sources, in a fixed shape
Don’t accept free text. Ask for a structured answer that names the chunks it relied on and says whether they answered the question at all:
from pydantic import BaseModel
class Answer(BaseModel):
answer: str
sources: list[str] # ids of the chunks used, such as "policy-s3"
found: bool # False if the sources do not answer the question
Now the model has to commit to something you can check.
Defence three: check in code
Every id in sources must be one of the chunks you actually sent. If found is false, or sources is empty, or an id is one you never sent, don’t send the answer. Send “a person will reply” instead, and pass the chat to the team with everything gathered so far.
The first two defences ask the model to behave. The third doesn’t depend on it: it is a rule enforced where the model can’t talk its way past.
A wait is cheaper than a wrong answer
Replying that a person will reply can feel like a failure. Compare what each outcome costs. A confident wrong answer about a refund can mean money paid out wrongly, or an angry customer promised something the policy doesn’t allow. A short wait for a person costs far less.
What to do this week
Write ten questions your documents do not answer, such as places you don’t deliver to or products you don’t sell, and send them to your assistant. Count how many get a confident answer. If it is more than zero, add the three defences above, run the same ten again, and keep them in your test set so the number stays at zero.
Adapted from Ship Real AI, Module 7, section 7.6.