concept

Capstone design and implementation plan

Tenant-scoped canonical response and exact mock proposal validation; not semantic retrieval.

Formal Syntax & Structure

artificial-intelligence syntaxartificial-intelligence
answer(question, tenant, docs, aliases, mode, mock)

Working Example

Example Snippetartificial-intelligence
def answer(question, tenant, docs, aliases, mode, mock):    # Identity and tenant come from the authenticated host, not the model.    # aliases are an explicit approved mapping, not a learned retriever.    if mode not in ("lookup", "mock_rag"):        raise ValueError("unsupported mode")    topic = aliases.get(question.strip().casefold())    allowed = [d for d in docs if d["tenant"] == tenant               and d["active"] is True and d["approved"] is True               and d["topic"] == topic]    abstain = {"status": "abstain", "value": None, "citations": []}    if topic is None or not allowed or len({d["value"] for d in allowed}) != 1:        return abstain    evidence = sorted(allowed, key=lambda d: d["id"])[0]    if mode == "mock_rag":        # Only authorized evidence enters the provider context.        proposal = mock.get(question, None)        if (type(proposal) is not dict or set(proposal) != {"value", "citation"}            or type(proposal["value"]) is not str            or proposal["value"] != evidence["value"]            or proposal["citation"] != evidence["id"]):            return abstain    return {"status": "answer", "value": evidence["value"],            "citations": [evidence["id"]]}
docs = [dict(id="a1", tenant="A", topic="hours", active=True,             approved=True, value="09:00-17:00"),        dict(id="b1", tenant="B", topic="hours", active=True,             approved=True, value="10:00-16:00")]aliases = {"hours": "hours", "ساعت": "hours"}mock = {"hours": {"value": "09:00-17:00", "citation": "a1"}}print(answer("hours", "A", docs, aliases, "lookup", mock))print(answer("hours", "B", docs, aliases, "mock_rag", mock))print(answer("ساعت", "B", docs, aliases, "lookup", mock))