Stage 7 · Master
LLM Foundations for Operators
How LLMs Actually Work
Tokens, context windows, temperature, and why models hallucinate.
What Is an LLM?
A Large Language Model (LLM) is a neural network trained on trillions of tokens of text. It predicts the next token in a sequence given the preceding context. That is all it does — but this simple mechanism produces remarkably capable language understanding and generation.
For SRE teams, LLMs are useful because they can reason over natural-language runbooks, summarize incidents, generate queries, and assist with troubleshooting. But they are probabilistic — they can be wrong, and they do not know what they do not know.
An LLM generates text based on patterns learned during training. It does not look up facts in a database. This is why RAG (Retrieval-Augmented Generation) matters — it gives the model access to your actual runbooks and docs.
Tokenization
Models do not read text character by character. They break input into tokens — pieces of words. Common words are one token. Rare words or technical terms may be split into multiple tokens. This directly affects cost and speed.
import tiktoken
enc = tiktoken.encoding_for_model("gpt-4")
tokens = enc.encode("kubectl get pods --namespace production")
print(f"Token count: {len(tokens)}")
print(f"Tokens: {[enc.decode([t]) for t in tokens]}")Each token is a chunk of text. Longer prompts consume more tokens and cost more. Understanding tokenization helps you write concise prompts.
Rough rule of thumb: 1 token is approximately 4 characters of English text, or about 0.75 words. A typical runbook page is 500 to 1000 tokens.
Context Window
The context window is the maximum number of tokens a model can process in a single request — input tokens plus output tokens combined. GPT-4 supports 8,192 tokens. GPT-4 Turbo supports 128,000. Claude 3 supports 200,000.
| Model | Context Window | Good For |
|---|---|---|
| GPT-3.5 Turbo | 16K tokens | Quick classification, short summaries |
| GPT-4 | 8K tokens | Complex reasoning, small runbooks |
| GPT-4 Turbo | 128K tokens | Full incident transcripts, large docs |
| Claude 3 Opus | 200K tokens | Massive context, entire codebases |
Sending 100K tokens to GPT-4 Turbo costs roughly $0.30 per request. At 100 requests per hour, that is $30/hour. Design your prompts to include only the context the model actually needs.
Temperature & Randomness
Temperature controls how creative or deterministic the model is. Lower temperature means more predictable, consistent output. Higher temperature means more varied, surprising output.
import openai
# Deterministic: same input, same output
response = openai.ChatCompletion.create(
model="gpt-4",
temperature=0.0,
messages=[
{"role": "system", "content": "You are an SRE assistant."},
{"role": "user", "content": "What causes high p99 latency?"}
]
)
# Creative: varied output each time
response = openai.ChatCompletion.create(
model="gpt-4",
temperature=0.7,
messages=[
{"role": "system", "content": "You are an SRE assistant."},
{"role": "user", "content": "Suggest a runbook title for Redis outages."}
]
)For operational tasks like classification, triage, and extraction, use temperature 0. For brainstorming or naming, use 0.5 to 0.9.
Why Models Hallucinate
Hallucination is when a model confidently states something that is factually wrong. It happens because the model optimizes for plausible-sounding text, not truth. It fills gaps with patterns from training data, even when those patterns are incorrect for your specific infrastructure.
- Training data is outdated — your infrastructure changed since the model was trained.
- The model has never seen your specific Kubernetes cluster or deployment patterns.
- It conflates similar-sounding services, endpoints, or procedures.
- It generates plausible but fabricated commands, metrics, or log entries.
Always ground your LLM responses in retrieved context from your actual runbooks, incident history, and documentation. RAG is the single most effective technique against hallucination in operational workflows.
Choosing the Right Model
Not every task needs the most powerful model. A simple classification task (is this alert P1 or P2?) can use a smaller, cheaper, faster model. Complex root-cause analysis benefits from a larger model with a bigger context window.
| Task | Recommended Model | Why |
|---|---|---|
| Alert classification | GPT-3.5 Turbo or Claude Haiku | Fast, cheap, sufficient |
| Runbook summarization | GPT-4 or Claude Sonnet | Needs to follow long context accurately |
| Root-cause analysis | GPT-4 Turbo or Claude Opus | Complex reasoning over large context |
| Code generation | GPT-4 or Codex | Strong code understanding |
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.