Always free. For everyone.
Course outline
Module 10 of 20 · AI inputs and outputs

Ground answers in approved sources

Retrieve relevant material, respect access, and abstain when support is missing. This module has 3 lessons and takes about 1h 50m. Each lesson has a practice exercise that runs real Python in your browser and a short quiz.

Start module 10 in the Learning Lab
LESSON 1 OF 3

Retrieve a simple source

25 minAI automation
WHAT YOU WILL DO

Return matching document ids in order using case-insensitive substring search. An empty or whitespace query returns an empty list.

Retrieval finds source material before an answer is drafted. A small keyword index is enough to demonstrate the flow. Larger systems may use search or embeddings.

Return document ids whose text contains the query, ignoring case. Preserve the input order and return no results for an empty query. This is lexical search, not semantic retrieval.

Finding relevant text does not make it authoritative or current. Keep source ownership and version information with each document.

See it in action

example.pyPython 3
def solve(query, documents):
    query = query.strip().lower()
    if not query:
        return []
    return [doc["id"] for doc in documents if query in doc["text"].lower()]
print(solve("repair", [{"id":"s1","text":"Repair hours"},{"id":"s2","text":"Training dates"}]))
Keep this in mind

Finding relevant text does not make it authoritative or current. Keep source ownership and version information with each document.

LESSON 2 OF 3

Filter sources by access

25 minAI automation
WHAT YOU WILL DO

Return ids for documents explicitly marked public=True or listing the user in allowed_users. Missing access fields grant no access.

A search result must respect the current user access rules. Filtering only after generating an answer is too late if restricted text has already reached the model.

This simulation uses public documents and documents with an explicit allowed_users list. Return ids of sources that are public or list the user.

Enforce access in the application and data layer. A prompt telling the model to ignore private documents is not access control.

See it in action

example.pyPython 3
def solve(user, documents):
    return [doc["id"] for doc in documents if doc.get("public") is True or user in doc.get("allowed_users", [])]
print(solve("u1", [{"id":"public","public":True},{"id":"private","allowed_users":["u2"]},{"id":"mine","allowed_users":["u1"]}]))
Keep this in mind

Enforce access in the application and data layer. A prompt telling the model to ignore private documents is not access control.

LESSON 3 OF 3

Practical: Abstain without supporting evidence

60 minAI automation
WHAT YOU WILL DO

Return a cited draft only when non-empty answer text appears exactly in the named allowed source. Otherwise return {"status":"review"}.

A grounded answer should cite an allowed source. If no source supports the answer, return an explicit request for review instead of filling the gap.

This deliberately narrow example uses extractive answers: the proposed answer must appear exactly within the cited source text. The allowed_sources dictionary is already filtered for this user.

A citation check is only one part of evaluation. It does not detect stale sources, misleading excerpts, or every semantic error.

GUIDED PRACTICAL · 60 MIN

Your experiment plan

Use the browser editor or the notebook. All records and AI responses are fictional. No network calls, credentials, or real messages are used.

  1. Build a three-document fictional workshop knowledge base with one restricted source.
  2. Run the example and predict its result before changing it.
  3. Complete the function in Practice and run the checks. Add your own normal, empty, and failure cases.
  4. Try an unsupported answer and a restricted source id.
  5. Save the notebook with your observations and explain one limitation of the simulation.

What to hand in

  • A retrieval, access, and citation flow with an explicit no-answer path.
  • A test table with inputs, expected outputs, actual outputs, and one revision.
Reflect on your results

How will you retire an outdated source?

The automatic exercise checks the core code behaviour. Review observations and written deliverables yourself or with a mentor.

See it in action

example.pyPython 3
def solve(answer, source_id, allowed_sources):
    source = allowed_sources.get(source_id)
    if not answer.strip() or not isinstance(source, str) or answer not in source:
        return {"status":"review"}
    return {"status":"draft", "answer":answer, "source_id":source_id}
print(solve("Open at 9", "s1", {"s1":"Open at 9 on weekdays."}))
Keep this in mind

A citation check is only one part of evaluation. It does not detect stale sources, misleading excerpts, or every semantic error.

ABOUT THE LEARNING LAB

Free, open and run by a nonprofit.

This page is part of AI Automation, a free course of 20 modules and 60 lessons in the engineering.fit( ) Learning Lab. The Learning Lab is built and run by engineering.fit( ), a nonprofit founded by Abdullateef Opeyemi Bakare that helps African engineering students gain research experience. You do not need an account or pay a fee to learn.

Course outline · Project lab · Visit engineering-fit.org