AI Foundations for Developers COURSE·LESSON 41 OF 410 completed

Capstone: Evaluate and Extend the Assistant

Add executable acceptance checks

Append this code to the baseline script from the previous lesson in the Python compiler. The checks verify initial evidence selection, abstention, and access filtering.

python
cases = [
    ("refund policy", "public", {"refund-v2"}),
    ("reset password", "public", {"account-v1"}),
    ("download CSV exports", "public", {"export-v1"}),
    ("internal incident response", "public", set()),
    ("internal incident response", "staff", {"staff-v1"}),
    ("lunar weather", "public", set()),
]
passed = 0
for question, audience, expected in cases:
    result = assistant(question, audience)
    actual = {item["id"] for item in result["evidence"]}
    assert actual == expected, (question, actual, expected)
    assert result["status"] == ("evidence" if expected else "abstain")
    passed += 1

for bad in ["", " " * 3, "x" * 1001]:
    try:
        assistant(bad)
    except ValueError:
        passed += 1
    else:
        raise AssertionError("Invalid input accepted")

print("Passed", passed, "checks")  # Passed 9 checks

# A known limitation: semantic paraphrases need a better retriever.
result = assistant("I want my money back")
print("Paraphrase:", result["status"])  # Paraphrase: abstain

Passing these nine checks demonstrates these nine behaviors on this corpus. It does not establish general language understanding, strong security, or production readiness.

Introduce generation behind a narrow adapter

The following is architecture pseudocode, not runnable API code. An actual hosted integration belongs behind a trusted server boundary; local inference needs a suitable runtime and device resources.

text
PSEUDOCODE
evidence = retrieve_authorized_sources(question, authenticated_user)
if no adequate evidence:
    return abstain
candidate = model_adapter.generate(
    instructions = evidence_only_answer_contract,
    question = question,
    sources = evidence,
    output_schema = {answer, source_ids, needs_clarification}
)
validate_schema(candidate)
reject source_ids not present in evidence
check important claims against cited passages
if unsupported or consequentially uncertain:
    return review_or_abstain
return candidate

Schema checks and source-membership checks can be deterministic. General claim-support checking is harder and may require domain rules, a separately evaluated model judge, or human review. Do not imply that membership validation alone proves grounding.

Your next experiments

Add 20 paraphrased questions and 10 unsupported questions. Test the custom-order exception, tenant isolation, deleted sources, changed policy versions, and instructions hidden in source text. Measure retrieval separately from answer quality. Compare the baseline against an embedding retriever on exactly the same fixtures.

Try an adversarial document that says “Ignore prior instructions.” The baseline returns text without acting on it. Once generation is introduced, evaluate whether the candidate answer follows the injected instruction, and ensure tool permissions cannot expand.

Final review with answers

Prompting, retrieval, or fine-tuning for changing policy text? Retrieval is the first candidate because it can supply current source versions without updating model weights.

What changes when a model is added? Language interpretation and generation become probabilistic components requiring additional quality tests, budgets, and failure handling.

What makes an AI application dependable? A well-defined task, authorized evidence, bounded actions, validated outputs, representative evaluations, observability, and a recovery path. Model capability is one part of that design.

Learn at your own pace0 / 41 lessons complete