Skip to lesson content

THE ILLUSTRATED LLM TUTORIAL / 10 OF 15

Real-World Applications and Examples

Design an evidence-grounded application and distinguish retrieval from live tool access.

Try the example ↓
Real-World Applications and Examples: Question: Ask about the return policy; Retrieve: Find relevant policy evidence; Answer: Include the source ID; Verify: Check support for the answer
Lesson 10 visual guide · Read the four steps, then explore the explanation below.
  1. 01QuestionAsk about the return policy
  2. 02RetrieveFind relevant policy evidence
  3. 03AnswerInclude the source ID
  4. 04VerifyCheck support for the answer

Choose the task and evidence

LLMs can draft text, summarize, assist with code, extract fields, and answer questions. A practical system starts with a specific task, authorized input, and an evaluation set rather than a general promise of intelligence.

Retrieval-augmented generation

RAG retrieves relevant content and places it in the model context. A useful answer should be supported by the retrieved text and cite its source. Retrieval quality, permissions, stale documents, and unsupported answers all require handling.

Tools for changing information

A policy document can answer a return-policy question. Current order status needs an authorized order-system lookup. Do not assume a language model knows live records simply because it has a company knowledge base.

Other modalities and workflows

Multimodal models can process supported image/audio inputs. Code generation still needs tests. Summaries need checks for omissions and unsupported statements. High-impact workflows require appropriate review and controls, not merely fluent output.

Worked example

This lexical retriever chooses between two tiny policy documents. It demonstrates retrieval and source tracking, not embeddings or LLM generation.

Download lesson 10 Python example

Python 3 / standard library
import re

docs = {
    "P1": "Unused items can be returned within 30 days.",
    "P2": "Standard shipping usually takes 5 days."
}
query = "How many days before unused items can be returned?"

def words(text):
    return set(re.findall(r"[a-z]+", text.lower()))

scores = {key: len(words(query) & words(text)) for key, text in docs.items()}
best = max(scores, key=scores.get)
print("Source:", best)
print("Evidence:", docs[best])

Expected output

Source: P1
Evidence: Unused items can be returned within 30 days.

P1 wins because it shares more query terms. A production retrieval system may use semantic and keyword search together, reranking, access checks, and confidence or abstention logic.

Practice and self-check

Common mistake

Retrieved text is evidence, not trusted instructions. A document saying ignore the user should not gain control of the application.

Student tasks

  1. Add a warranty policy and a question that retrieves it.
  2. Design an abstention response when none of the documents answers the question.
  3. For Where is my order?, list the needed authorization and live data source.
Checkpoint — open after attempting the tasks

An acceptable abstention is: The supplied documents do not state that. Order status needs identity/access verification and an authorized order lookup.