Papa Programmer
Lesson 10 of 20

Choosing useful sources

6 min read

Optional

The agent trusts what it reads

A model has no instinct for which page to believe. If a retrieved passage says that refunds take 90 days, the agent will write that down as fact, even when the policy says 30. The wording of the answer will be fluent either way. Fluency is not evidence.

That is why source choice is a design decision, not a detail. It is the best defence against an AI hallucinationAn answer that sounds confident but is false. The model wrote text that fits the pattern instead of text that is true. that comes from bad input, and it decides how much you can trust Retrieval-augmented generationA method where an app searches sources at question time and adds selected passages to the model's context. Updated information can inform later answers once it is available to retrieval, but the results and answers still need checking. in practice.

Three questions for every source

Ask these before you add a source to an agent's reach.

  1. Is it relevant? Does it cover the question, or only the topic? A page about shipping in general does not answer a question about shipping to Norway.
  2. Is it trusted? Who wrote it? An official policy page, a database you control and a signed contract rank above a forum post or an anonymous blog.
  3. Is it current? When was it last updated? A price list from last year is worse than none, because the agent will not know that it has expired.

A source can pass one test and fail another, so check all three.

Rank the sources in code

When several sources return passages, the program can rank them with simple rules before the model reads any.

python
from datetime import date

TRUST = {"policy": 3, "help_centre": 2, "forum": 1}

def rank(passages, today=date(2026, 11, 15)):
	def value(passage):
		age_days = (today - passage["updated"]).days
		fresh = 1 if age_days < 365 else 0
		return (TRUST[passage["kind"]], fresh)
	return sorted(passages, key=value, reverse=True)

passages = [
	{"kind": "forum", "updated": date(2026, 10, 1), "text": "Refunds take 90 days."},
	{"kind": "policy", "updated": date(2026, 6, 1), "text": "Refunds are accepted within 30 days."},
]
print(rank(passages)[0]["text"])

The policy page ranks first, even though the forum post is newer, because trust comes before freshness in this rule. Choose the order that fits your data. For a news agent, freshness might come first.

When sources disagree

Disagreement is a signal, not a nuisance. Pick one of these responses and make it a rule in the instructions.

  • Prefer the more trusted source when one clearly outranks the other.
  • Show both and say where each came from, when the user should decide.
  • Say that you do not know when the sources conflict and nothing ranks higher.

Whatever the choice, ask the agent to name its sources in the answer. A citation lets a reader check the claim in seconds and lets you find the bad source when something goes wrong.

Relevant, trusted, currentCheck all three. A source can fail any one of them.
Rank before the model readsOrder passages by trust and freshness with simple rules in code.
Name the sourceAsk the agent to cite where each fact came from so a reader can check.

Your reading position is saved

0%

0 of 20 complete

Contents

Learning tools