SYSTEM 1: THE ARTIST (Probabilistic) SYSTEM 2: THE ENGINEER (Deterministic)
────────────────────────────────────── ──────────────────────────────────────
• Machine Learning • Rule-Based (THIS PROJECT)
• Learns from data • Explicit if-else / dictionary logic
• Flexible but unpredictable • Rigid but 100% traceable
• Can hallucinate • ZERO hallucination risk
• Black box • White box — full transparency
RuleBot is a White Box system:
- Traceability: Input → Logic → Output. No mystery.
- Safety: Zero hallucination risk. 100% hard-coded.
- Compliance: Used in Finance & Healthcare AI systems.
# BAD — High technical debt, O(n) complexity
if user_input == "hello":
print("Hi!")
elif user_input == "bye":
print("Goodbye!")
elif user_input == "joke":
print("...")
# ...imagine 30 more elif blocksProblems: Linear O(n) complexity, hard to maintain, cascading failures.
# GOOD — O(1) lookup, clean, scalable
responses = {
"hello": ["Hi!", "Hey there!"],
"bye": ["Goodbye!", "See you!"],
"joke": ["Why do programmers..."],
}
reply = responses.get(user_input, "I do not understand.")raw_input = input("You: ") # Raw feed
clean_input = raw_input.lower().strip() # Normalized
# "Hello " → "hello"
# "BYE" → "bye"
# " Hi! " → "hi!"# O(1) dictionary lookup with fallback
for keyword in KNOWLEDGE_BASE:
if keyword in clean_input:
matched = KNOWLEDGE_BASE[keyword]
break
response = random.choice(matched) if matched else FALLBACKprint(f"RuleBot: {response}")
if is_exit:
break # Clean kill commandwhile True: # ← HEARTBEAT STARTS
raw = input("You: ") # ← INPUT
clean = sanitize(raw) # ← SANITIZE
response, is_exit = get_response(clean) # ← PROCESS
print(response) # ← OUTPUT
if is_exit:
break # ← KILL COMMANDThe while True loop is the heartbeat — it keeps the chatbot alive until the exit command fires the break.
This architecture is directly used in production today:
┌────────────────────────────────────────────┐
│ USER INPUT │
└────────────────────┬───────────────────────┘
│
▼
┌────────────────────────────────────────────┐
│ RULE-BASED GUARDRAILS ← YOU ARE HERE │
│ (Filtering, Redaction, Blocking) │
│ e.g. NVIDIA NeMo, Llama Guard │
└────────────────────┬───────────────────────┘
│
▼
┌────────────────────────────────────────────┐
│ LARGE LANGUAGE MODEL │
│ (Probabilistic Core) │
└────────────────────────────────────────────┘
Time to Execute
│
5s ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─/ ← If-Elif O(n)
│ /
1s ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ /
│ /
│ ────────────────────────────────────── ← Dictionary O(1)
0ms ───────────────────────────────────────▶
0 100 1000 10000
Number of Rules (Scale)
Dictionary lookup stays flat at O(1) regardless of scale.
| File | Responsibility |
|---|---|
chatbot.py |
Core brain — knowledge base, sanitization, response engine, terminal loop |
app.py |
Streamlit frontend — UI, session state, chat display, sidebar stats |
requirements.txt |
Dependency management |
README.md |
Project overview and usage guide |
ARCHITECTURE.md |
This file — deep technical explanation |
REFLECTION.md |
Personal learning notes for portfolio |
Architecture Briefing