30 Days of AIDay 14 of 30 · Week 2: Applied AI & APIs
Course outline▾

Week 3 · Infrastructure & Hosting

  1. Day 15Introduction to AI Infrastructure: Hardware, Runtimes, and ComputeComing soon · 2026-10-15 · 7 PM IST
  2. Day 16Local Model Execution: Running Open-Weight LLMs Securely (Ollama, vLLM)Coming soon · 2026-10-16 · 7 PM IST
  3. Day 17Containerizing AI Workloads: Writing Production Dockerfiles for Python APIsComing soon · 2026-10-17 · 7 PM IST
  4. Day 18Docker Compose for Multi-Container AI Stacks (Web UI, Vector DB, LLM Engine)Coming soon · 2026-10-18 · 7 PM IST
  5. Day 19Kubernetes for AI 101: Pods, Deployments, and Services for Model ServingComing soon · 2026-10-19 · 7 PM IST
  6. Day 20Persistent Storage in Kubernetes: Managing State, Weights, and Vector IndicesComing soon · 2026-10-20 · 7 PM IST
  7. Day 21High-Performance Networking: Configuring Ingress and Egress for AI ClustersComing soon · 2026-10-21 · 7 PM IST

Week 4 · Enterprise Workflows

  1. Day 22Autonomous Agents: From Passive LLMs to Goal-Driven ExecutionComing soon · 2026-10-22 · 7 PM IST
  2. Day 23Tool Use & Function Calling: Connecting LLMs to APIs, Databases, and ShellsComing soon · 2026-10-23 · 7 PM IST
  3. Day 24Multi-Agent Orchestration: Supervisor, Worker, and Evaluator PatternsComing soon · 2026-10-24 · 7 PM IST
  4. Day 25Automated CI/CD: Automating the Software Lifecycle for AI ModelsComing soon · 2026-10-25 · 7 PM IST
  5. Day 26Zero-Trust Security for AI: Sandboxing Ephemeral Execution & Model EgressComing soon · 2026-10-26 · 7 PM IST
  6. Day 27Observability & Tracing for Agentic Systems (Telemetry, Logs, and Metrics)Coming soon · 2026-10-27 · 7 PM IST
  7. Day 28Human-in-the-Loop Architecture: Machine Second, Human First in PracticeComing soon · 2026-10-28 · 7 PM IST
  8. Day 29Managing Technical Debt, Drift, and Model Governance in Enterprise ITComing soon · 2026-10-29 · 7 PM IST
  9. Day 30The 10-Year Horizon: Architecting IT Strategy for the AI-Native EnterpriseComing soon · 2026-10-30 · 7 PM IST
Open the course page →

Day 14: RAG Evaluation and Hallucination Guardrails

2026-10-14 · 7 min read

A RAG pipeline is powerful, but it adds new places to fail. The model is only as good as what you hand it, and when it is handed the wrong thing it does not say "I'm confused". It answers confidently.

In plain terms: An open-book exam only works if the student opens the right book. Hand them the wrong chapter and they will write a polished, convincing, wrong answer.

Wrong retrieval, confident wrong answer QuestionWhat is the REIT's yield?Retrievalpulls the wrong documentLLMwrites fluently from itAnswerconfident, and wrong A hallucination can start in retrieval, not in the model.
If the retrieval step pulls the wrong document, the LLM will still write a fluent answer from it. The result is confident and wrong, so a hallucination can start in retrieval and not in the model.

1. Measure the two halves

You evaluate a RAG system by scoring its two halves separately, because they fail in different ways.

  • Context relevance asks whether the retrieved documents actually contain the answer to the user's question. This checks the retrieval step.
  • Faithfulness asks whether the generated response is strictly derived from the retrieved context, or whether the model brought in outside information. This checks the generation step.
Two things to measure Context relevanceDid we retrievethe right paragraphs?Checks the retrieval stepQuestion vs contextFaithfulnessIs the answer built onlyfrom that context?Checks the generation stepAnswer vs contextGood retrieval plus a faithful answer is a trustworthy RAG system.Score both. A fault in either one breaks the answer.
Context relevance checks whether the retrieved documents actually contain the answer. Faithfulness checks whether the generated answer is strictly derived from the retrieved context instead of invented.

2. Spot an unfaithful answer

Faithfulness is checked claim by claim. If the context says the REIT paid a dividend in Q3 and the answer adds that its yield is 7.4%, that second claim is not in the context. It was invented, and that is a hallucination, even though it sounds perfectly plausible.

Faithfulness: claim by claim Retrieved context"The REIT paid a dividend in Q3."Answer: The REIT paid a dividend in Q3.supported✓Answer: Its yield is 7.4%.not in the context✗The invented 7.4% is a hallucination.Example text is illustrative.
A faithfulness check compares each claim in the answer with the retrieved context. A claim the context supports passes. A claim that is not in the context, such as an invented yield percentage, is flagged as a hallucination. The example text is illustrative.

3. Guardrails: an LLM as judge

You can automate that check. A secondary, smaller LLM acts as a judge in the pipeline. Before the final answer reaches the user, the judge compares it with the retrieved text and decides whether to show it or block it. When a check fails you can retry retrieval, or return "I don't know". Judges can be wrong too, so sample their decisions and review them.

A smaller LLM acts as the judge Context retrieved Answer from LLM Judge small LLM Show itBlock itBefore the user sees the answer, the judge checksit against the retrieved text for factual consistency.Failed checks can retry retrieval, or answer "I don't know".Judges can be wrong too, so sample and review their calls.
A secondary, smaller LLM acts as a judge. Before the user sees the answer, it compares the answer to the retrieved text and either lets it through or blocks it. Judges can be wrong too, so teams sample and review their decisions.

Here is the idea as a short Python sketch. The llm_judge function stands in for a call to a small model that you prompt to compare an answer against a context.

def guarded_answer(question: str) -> str:
    chunks = search(embed(question), top_k=3)
    answer = generate(question, chunks)

    # Judge: is every claim in the answer supported by the retrieved text?
    verdict = llm_judge(
        "Reply SUPPORTED or UNSUPPORTED. Is every claim in the answer "
        "backed by the context?\n\n"
        f"Context: {chunks}\n\nAnswer: {answer}"
    )
    if verdict.strip().upper().startswith("SUPPORTED"):
        return answer
    return "I could not find a reliable answer in the documents."

Keep a small test set of real questions with known answers, and run it every time you change chunking, the embedding model or the prompt. That is how you catch a regression before your users do.

Coming Up Next

Day 15: Introduction to AI infrastructure: hardware, runtimes and compute.

#AIQuality #MLOps #Hallucination #TechLeadership #DataGovernance