Make answers cite their sources and admit gaps

You will be able to write a prompt that makes a model answer only from retrieved text, cite it, and say when it cannot answer.

When you build a tool that looks things up in your own documents before it replies, the search step only decides which text the model gets to read. It puts no limit on what the model writes. Models carry a lot of general knowledge about how employers tend to run benefits, leave and claims. When your documents leave a gap, the model fills it from that knowledge unless you instruct it otherwise. In a policy assistant, an HR tool, or anything else whose answers have to come from your organisation's own files, that habit causes harm. You control it with the answering prompt, which is the prompt that sets out what the model is allowed to use when it replies.

Daniel built a retrieval-based tool for his firm's HR handbook, and the search side of it worked. A colleague asked whether the firm covered gym memberships. Nothing in the handbook mentions gyms. Retrieval still returned the five closest chunks. They covered medical benefits, the wellness day and the flexible benefits scheme. From those, the model wrote a confident paragraph stating that gym fees were claimable under flexible benefits up to an annual limit, with a citation to a section that says nothing about gyms. The colleague put in a claim, it was rejected, and Daniel had to explain what had gone wrong.

What to put in the answering prompt

Your prompt needs three instructions, stated plainly:

Answer using only the passages provided. If the passages don't contain the answer, say it couldn't be found in the documents, and don't guess. Don't use outside knowledge about how other companies, or the law, deal with the matter.

Pair the second instruction with a fixed phrase, a set wording the model must use whenever the answer is missing. An HR tool might use "I could not find this in the HR documents. Please check with HR." Your code can spot and count a sentence that never changes much more easily, and people find it clearer than an apology the model composes fresh each time.

Next comes the layout. Place the retrieved passages inside a clearly marked block, give every passage an ID and a source label, and put the user's question after the block, introduced by a label such as "Question:". Daniel's version numbers each passage, tags it with the document it came from, and writes "Question:" ahead of whatever the user typed. The sharper the division between passages and question, the less the model mixes the passages, the question and its own background knowledge into one answer.

Last, instruct the model to add the ID or source label of the supporting passage after each statement.

Building and checking citations in code

In lesson 3.3 you saved metadata alongside every chunk, and you use it at this point. When the model returns a passage ID, your code looks up the document, section and page held for that ID and prints a readable reference, for example "Claims Policy, section 4.2, page 7". The reference comes from stored data, so the model never types it.

You practised citing sources in chat in the course "Working with AI assistants", lesson 5.2, "Make it quote and point to the source". Inside an application you can test the same habit automatically. Compare every ID in the answer against the list of passages you sent. If the model cites a passage that was never retrieved, you have a drifted answer, and your code can flag it before it reaches the user.

This check has a limit. A valid ID shows the passage was sent. It does not show the passage supports the claim. Daniel's gym answer pointed to a real section whose text said nothing like what the answer stated. For this reason the next two habits matter: check retrieval first when an answer is wrong, and put the sources in front of the user.

Tracing a wrong answer to retrieval or the prompt

Faced with a bad answer, most people start editing the prompt. In a retrieval system that is usually the wrong place to start. Most wrong answers come from retrieval: the passage holding the answer was never found, and the model was working from the wrong material.

Open the passages that were actually sent before you touch the prompt. If the right passage is absent, the fault lies in chunking, embedding or search, and rewording the prompt won't repair it. If the right passage is present and the answer is still wrong, look at the prompt or the model.

Daniel added a debug mode that prints the retrieved passages beneath each answer. With it, tracking down a bad answer took minutes instead of an afternoon, since he could tell at a glance which half of the system had failed.

Letting users check the sources

Give users citations detailed enough to find the page themselves. People trust an answer more when they can verify it, and they spot errors the tool has no way of catching. Daniel's tool now displays the answer, a source beneath each sentence, and a link that opens the document at that page. Wrong answers now get reported within a day, usually along with the exact passage that disagrees. For anything that matters, such as a claim or a leave application, a staff member should open the cited section and read it before acting.

Count an honest "I could not find this" as a correct answer, and write tests that check for it deliberately, as Daniel now does. The activity below has you write the answering prompt and try it on two questions your documents cannot answer.

Write the answering prompt for your tool. Test it with two questions your documents cannot answer.

Course

Junxiong-WFG Organisation is an authorised representative of AIA Financial Advisers Private Limited (Reg. No. 201715016G).