AI & Data3 January 20278 min read

Build Lab: From Chain to Governed Agent — Part 3 of 8

Retrieval with evidence and source boundaries

Adding retrieval to a chain is easy. Proving which approved source supported each sentence is the hard part. Part 3 of Build Lab: From Chain to Governed Agent sets the source boundary before the query, treats evidence as a data structure the answer must reference, and tests what the retriever finds before judging what the model writes.

#RAG#LangChain#AI Engineering#AI Governance#Evidence

By the end of Part 2, the illustrative assistant at a public service counter has a versioned prompt and a structured output. It can detect the language and intent of a request and return a clean object. What it cannot do yet is say anything reliable about the service, because the only knowledge it has is what the model learned in training. The next step on the routine path is the obvious one: retrieve approved service information, and produce a structured answer with source references.

Retrieval is easy to add. A tutorial can load some documents, split them, embed them and return the top four passages in a few lines. The difficult questions arrive afterwards. Which documents was the retriever allowed to search? Was the passage it used the current version? Which sentence in the answer came from which passage? If a reviewer asks next month why the assistant told someone the wrong opening hours, can anyone show them?

Retrieval in a governed service is a controlled read of approved sources: set the source boundary before the query runs, make every claim in the answer point to a passage the system can show again, and test what the retriever finds before you judge what the model writes.

What the framework gives you

LangChain's retrieval documentation (checked on 25 November 2026) describes the usual building blocks: document loaders that return standard Document objects, text splitters, embedding models, vector stores and retrievers. It also describes three architectures. In 2-step RAG, retrieval always runs before generation, which the page describes as high control and low flexibility. In agentic RAG, an agent decides when and how to retrieve through tools. Hybrid RAG adds steps such as query enhancement and validation of the retrieval and the answer.

These are useful interfaces. They save a team from writing its own adapters for each vector store and model. They do not decide what belongs in the index, what a passage is allowed to support, or what happens when nothing relevant comes back. The documentation is candid about this in its own way: its page on retrieval has no section on citations, and its extended example handles sources through an instruction in the system prompt. An instruction is a request to the model. It is not a control.

For the routine path at the counter, 2-step RAG is the right starting point. The question is narrow, the sources are known, and the team wants to control every retrieval. Agentic retrieval earns its place later, when the exception path needs to decide which of several sources to consult, and Part 4 gives that decision a graph to run in.

Set the boundary before the query

The most common retrieval failure in a public service is not a bad embedding. It is a good match from a document that should never have been searched: a superseded instruction, a draft awaiting approval, internal guidance for staff, or content for a different service with similar wording.

A source boundary answers four questions before the retriever runs.

  • Which collections are in scope for this step? The routine path searches approved public service content only.
  • Which status and version may be returned? Approved and current, never draft or superseded.
  • Which audience is the content for? Public guidance is not the same as staff procedure.
  • Which language versions are approved? A passage translated by the model on the fly is not an approved source.

Each answer becomes metadata on every chunk at ingestion, and a filter at query time. LangChain's vector store page (checked on 25 November 2026) shows similarity_search accepting k and a metadata filter, and notes that filter support varies by store. Check yours before relying on it.

Illustrative; check against the current documentation. Synthetic data; the filter syntax depends on the vector store.

from langchain_core.documents import Document

doc = Document(
    page_content="Collections are available on weekdays at the counter.",
    metadata={"source_id": "svc-guide-07", "version": "3",
              "status": "approved", "audience": "public", "lang": "en"},
)
vector_store.add_documents(documents=[doc], ids=["svc-guide-07-p2"])

hits = vector_store.similarity_search(
    question, k=4, filter={"status": "approved", "audience": "public"}
)
evidence_ids = {h.metadata["source_id"] for h in hits}

Filter before ranking, not afterwards. Post-filtering the top results can leave the answer with nothing, or with whatever was left once the right passages were removed. Permission-aware retrieval covers the same rule when the boundary is a person's entitlements rather than a document's status.

Evidence is a data structure

Part 1 made the model return a schema rather than prose. Retrieval extends that schema. The answer object now carries a list of citations, and each citation names a source, a version and a passage that were in the retrieved set for this request.

That one change makes three checks possible in plain code, after the model has answered and before anyone sees it.

  1. Every citation exists in the evidence set. A citation to a passage the retriever did not return is a fabrication, whatever it looks like.
  2. Every factual claim has a citation. No citation, no claim. A sentence about requirements, hours or fees with nothing behind it is removed or the answer is withheld.
  3. An empty evidence set produces a defined outcome. If nothing in the boundary matched, the assistant says it cannot answer from approved sources and offers a handoff. It does not fall back to the model's general knowledge.

None of this needs a framework. It needs the schema, the evidence set kept alongside the answer, and a validation step that is allowed to fail the response.

The evidence contract

The decision tool for this part is an evidence contract. Agree it with the content owner before building the index, then test each row.

FieldWhy it existsTest a team should be able to show
Source IDPoints to one approved documentEvery citation resolves to a document in the register
VersionShows which wording was usedA superseded version is never returned
Passage IDPoints to the exact text, not the whole documentThe passage can be shown again a month later
Status and audienceSets the boundaryDraft and staff-only content never appear in public answers
LanguageMarks approved language versionsA model translation is not cited as an approved source
OwnerNames who answers for the contentEach source has a named owner and review date
Retrieved setRecords what the model was shownThe trace holds the IDs for each request
Abstain ruleDefines what happens with no evidenceAn out-of-scope question produces a handoff, not a guess
Retrieval with evidence and source boundaries. Step 1, a question arrives with its language and intent detected. Step 2, the source boundary is applied before the query: approved, current, public content in an approved language only. Draft, superseded, staff-only and other-service content stays outside the boundary and is never searched. Step 3, the retriever filters first and then ranks the top results. Step 4, the evidence set records the source, version and passage IDs with the run. Step 5, the model drafts a structured answer with citations. Step 6, a citation check in plain code asks whether every citation is in the evidence set and every factual claim has a citation. If yes, the answer is released with its sources. If no, or if the evidence set is empty, the assistant abstains and offers a handoff to a person.INSIDE THE BOUNDARY1 QUESTIONLanguage andintent detected2 BOUNDARYApproved, current,public, approvedlanguage only3 RETRIEVEFilter first,then rank top k4 EVIDENCE SETSource, versionand passage IDskept with the run5 DRAFTStructured answerwith citationsOUTSIDE: NEVER SEARCHEDDraft, superseded, staff-only, other servicesblocked6 CITATION CHECK (CODE)Every citation in the evidence set?Every factual claim cited?IDsyesAnswer releasedwith its sourcesno, or empty setAbstain: cannot answer fromapproved sources; offer a personTest the retriever first: does the right passage appear, and does anything outside the boundary ever appear?
Set the boundary before the query, keep the evidence set with the run, and let a plain check fail the answer. No citation, no claim. CloudNala analysis; illustrative.

Test what it finds before what it writes

A fluent answer can hide a bad retrieval. Test the retriever on its own first, with a small set of questions and the passages that should come back for each. Include questions that should return nothing, questions where an old version is the closest match, and questions in each approved language. Measure whether the right passage appears in the retrieved set, and whether anything outside the boundary ever does.

Only then evaluate the answer: whether it uses the evidence, cites it correctly and abstains when it should. Add retrieval only when knowledge must change independently makes the same case for testing what the system finds first, and Part 7 of this series turns both into evaluation cases with pass and fail reasons.

What retrieval does not solve

Retrieval supplies evidence. It does not supply meaning, authority or trust.

  • Meaning. A passage that matches the words may answer the wrong question. RAG supplies evidence, not missing concepts, in Ontology Before Autonomy, shows why the concept should be resolved before retrieval runs.
  • Freshness. The index is a copy. Someone owns the process that removes superseded content, and someone checks that it ran. RAG is a data product, not a prompting trick covers ownership and lineage.
  • Instructions inside documents. Retrieved text is data. A passage that says "ignore previous instructions" must be treated as content to be quoted or rejected, never as a command.
  • Authority. A passage that says an official may waive a requirement does not let the assistant waive it.

How NalaTolika applies it

NalaTolika is a CloudNala concept and reference architecture for governed language interpretation. It has no customers, deployments, pilots, data or results. In its reference design, the routine path uses 2-step retrieval over approved service content only, filtered by status, audience and approved language version. Every answer that states a requirement carries the source, version and passage it used, and an answer with no supporting passage becomes a handoff to a person.

Next in the series: Stateful workflows with LangGraph. All parts are on the series page, and the companion insight is The framework is not the product.

Sources and limits: this article is CloudNala analysis. LangChain's retrieval and vector store documentation was checked on 25 November 2026; interfaces and filter support change between versions and between stores. The code is illustrative, uses synthetic data and has not been run as part of any CloudNala lab; no CloudNala code repository exists for this series. The evidence contract is a CloudNala recommendation. The counter scenario is illustrative and describes no department or organisation. NalaTolika is a concept with no deployments.

How CloudNala can help

CloudNala reviews retrieval designs against an evidence contract. We map the sources in your index to owners, status and audience, define the boundary for each workflow step, add citation and abstain checks to the answer schema, and build the small retrieval test set that shows what the system finds before anyone judges what it writes.


Work with CloudNala

CloudNala helps organisations move from technology ambition to practical execution across cloud, AI, data, platform engineering and digital services.

Whether you are exploring AI, modernising your cloud environment, building a public-sector digital service, or turning an idea into a working MVP, we can help you shape the roadmap and deliver the next step.

Book an AI Production Readiness Review or write to us at consult@cloudnala.co.za

Found this useful?

Share