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
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
- Add a warranty policy and a question that retrieves it.
- Design an abstention response when none of the documents answers the question.
- 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.
