Lesson 01 · Foundations

What an LLM Actually Is

One idea, and almost everything you'll build follows from it.

FDE skill · predict failure before you build
🎧 Listen to this lesson · ~5 min · narrated audiobook edition

⏱ ~6 min read · 🎧 5 min listen · ✎ 3 quizzes · 🧪 ~15 min exercise

You're going to spend your career building reliable systems on top of these models for customers. You cannot make something reliable if you don't know what it is. So we start with the one mental model that the rest of the course hangs off — the one that lets you look at a weird model behavior at a client site and say "of course it did that," instead of being surprised.

The whole thing, in one sentence

An LLM is a function that takes some text and outputs a probability distribution over what the next token should be.1 That's it. That is the entire machine.

A token is just a chunk of text — usually part of a word. To generate a full answer, the model runs a loop you already understand as an engineer:

text = "The capital of France is"
loop:
    dist  = model(text)        # a probability for every possible next token
    next  = sample(dist)       # pick one, e.g. " Paris"
    text  = text + next        # append it
    if next == END: break      # stop token

Predict a token, glue it on, feed the whole thing back in, predict again. This loop is called autoregression, and running it fast is all that happens when you call ChatGPT or Claude.2 There is no database lookup, no reasoning module, no fact-checker. One loop.

The engineer's reframe It's autocomplete(text) → text, trained on a large fraction of the internet. Where do the probabilities come from? During pretraining, the model read an enormous amount of text and adjusted billions of parameters until it got good at guessing the next token. Those frozen numbers are a lossy compression of the patterns in that text — not a lookup table of facts.1
Base vs. assistant Pretraining alone yields a base model — a pure document-continuer that answers a question with more questions if that's the likelier continuation. The helpful question-answering behavior you see in ChatGPT or Claude comes from a second, much smaller training stage on top. Karpathy's "Deep Dive" walks through both stages; the loop you just read is identical in each.

Why an FDE should care: four behaviors fall out for free

Here's the payoff. You don't have to memorize the model's quirks as a list — you can derive them from "it samples plausible next tokens from compressed text patterns."

1. It hallucinates — and that's not a bug

The loop always produces a plausible continuation. Plausible ≠ true. If a customer asks for a policy number the model never saw, the most plausible next tokens still look like a policy number — so it confidently invents one.3 Hallucination isn't a defect bolted on; it's what next-token prediction does when it lacks the fact. (Grounding it in real data — RAG — is a later lesson, and now you'll know exactly why it works.)

Karpathy's word for it In his "Busy Person's Introduction," Karpathy describes LLM output as dreaming internet documents — most dreams are accurate recall, some are confabulation, and the model can't tell you which is which. It's the same claim as this section, from the machine's point of view: everything it emits is a dream; some dreams happen to be true.

2. Same prompt, different answers

The model outputs a distribution; sample() picks from it. Turn the temperature up and picks get more random; down toward zero and they get near-deterministic. This is why an LLM call is not a pure function the way your other code is — a fact that will shape how you test and eval it.

3. It has no memory between calls

The only thing the model sees is the text in front of it — the context window. It doesn't "remember" your last message unless you resend it. Every bit of customer context the model needs must be in the input. "Chat history" is just your app re-pasting the conversation each turn.

Glossary cross-ref "Context window," "token," and "sampling" are the three terms customers most often use loosely in meetings. The glossary pins down each one the way this course uses them — worth a two-minute skim before your first scoping call.

4. Wording matters more than you'd expect

Output is conditioned entirely on input tokens, so changing the prompt changes the distribution. This isn't the model being fussy — it's the mechanism. It's also why prompt engineering is a real lever, not folklore (Lesson 03).

Optional intuition (skip if you like) No math needed today. The only quantitative idea worth holding: the output isn't one answer, it's a ranked list of likelihoods over ~100k possible tokens, and the model commits to just one before moving on. Everything downstream is that bet, repeated.

Check yourself — diagnose the failure

Retrieval beats re-reading. Don't scroll up: for each customer scenario, name the root cause from the model itself. Wrong picks stay live — try again.

Scenario A

A customer's support bot cited a refund policy — clause number and all — that does not exist in their handbook. What happened?

Scenario B

You send the identical prompt twice and get two different answers. The customer calls it "unreliable." What's actually going on?

Scenario C

A client insists the bot "forgot" a detail from ten messages ago, even though it handled it fine earlier. Most likely cause?

🤖 Get your work reviewed

No chat here — this box replaces it. Copy the prompt into any AI assistant (Claude, ChatGPT, Gemini…), then paste your work after it.

You are a senior AI engineer reviewing my work: my written diagnoses of three customer scenarios (a bot citing a nonexistent policy clause, identical prompts giving different answers, and a bot "forgetting" a detail from earlier in a long conversation). I've explained each failure in my own words, tracing it back to how an LLM actually works.

Grade each diagnosis as Strong / Adequate / Missing, with one sentence of evidence:
- Every explanation traces to the mechanism: the model samples plausible next tokens from compressed text patterns.
- Hallucination is framed as inherent to next-token prediction when a fact is absent — not a bug or misconfiguration.
- Non-determinism is attributed to sampling from a probability distribution (and I mention temperature's role).
- "Forgetting" is attributed to the context window — text that scrolled out is invisible, not deleted.

Be skeptical — challenge my weakest diagnosis first. Then ask me 2–3 follow-up questions a customer would ask in the room. Finish with the single highest-leverage improvement to my mental model.

My work follows below.
Primary source — watch this
The clearest no-math explanation of the machine you just met, from one of the field's best teachers. Watch the first half this week. When you're ready to go deeper, his 3.5-hour "Deep Dive into LLMs" covers the full training stack.
Your one tangible win You can now take any surprising LLM behavior a customer reports and trace it back to "it samples plausible next tokens from compressed text patterns." That single sentence is the foundation for prompting, RAG, agents, and evals — all coming up.
Questions? Confused about tokens vs. words? Curious how "reasoning" models fit this picture? Paste the relevant lesson section into any AI assistant (Claude, ChatGPT, Gemini…) and ask away — and for feedback on your scenario diagnoses, use the review-prompt box above.

Recommended learning

Hand-picked follow-ups if this lesson left you hungry. None are required — the primary source above comes first.

References

  1. Chip Huyen, AI Engineering: Building Applications with Foundation Models (O'Reilly, 2025) — foundation models & the language-model mechanism.
  2. Andrej Karpathy, "Deep Dive into LLMs like ChatGPT" (2025) — inference & the autoregressive loop.
  3. Andrej Karpathy, "A Busy Person's Introduction to LLMs" (2023) — hallucination as a property of next-token prediction.