How LLMs Actually Work
Jump to section
Why you need a mental model
You don't need to understand neurons and linear algebra. But having a basic idea of how LLMs work will help you write significantly better prompts. It's like driving — you don't need to be a mechanic, but it helps to know that fuel goes in the tank and not in the windshield washer reservoir.
Most prompting mistakes stem from misconceptions about what AI is and how it works. People expect AI to 'understand' their intent, 'remember' previous conversations, or 'know' current information. Once you understand reality, you stop making these mistakes and your prompts dramatically improve.
LLM = the world's most advanced autocomplete
A language model generates text by predicting further tokens from context. Modern products may also use internal reasoning, planning and tools. Autocomplete is a useful simplified analogy, not a complete description of every current system.
This doesn't mean the outputs are simple. Modern models have hundreds of billions of parameters and were trained on trillions of tokens of text. The result is a system that produces surprisingly coherent, useful, and often brilliant responses — but still based on prediction, not understanding.
Text is generated progressively in tokens. Some models also use internal reasoning and tools. A visible explanation is a user-facing output, not a faithful record of the full internal process. Judge quality by a verifiable result rather than explanation length.
Tokens: how AI reads your text
A token can be a word, part of a word, a character or a group of digits. Splitting depends on the tokenizer; numbers are not always split digit by digit. Check counts with the relevant provider’s tokenizer. Word-to-token ratios are rough estimates, especially across languages.
Context capacity depends on the specific model, product and plan; check current documentation and allow room for output. A chat may truncate or summarize older messages, or reject an oversized input. A large window does not guarantee accurate use of every detail.
Practical estimate: 1 token is roughly 0.75 English words. So 200K tokens is about 150K English words. For perspective: the entire Harry Potter and the Philosopher's Stone book has about 77K English words — it fits in the context window.
Temperature and top-p: why AI answers differently each time
For models that support it, temperature changes randomness in token selection. A lower value does not guarantee determinism or factual accuracy. Check the supported range and parameters for the specific model; some reasoning models restrict them.
An instruction such as “write factually” can change output style, but does not itself change the technical temperature setting. Distinguish generation settings from wording, and verify accuracy independently.
The attention mechanism: not all tokens are created equal
LLMs use a mechanism called 'attention.' When generating each token, the model 'weighs' all previous tokens — but not equally. It pays more attention to some than others. Practically, this means: instructions at the beginning and end of your prompt typically have more influence than those in the middle. This is known as the 'lost in the middle' effect.
Common myth: 'AI understands what I want.' It doesn't. AI predicts the statistically most likely continuation of your text. The more precisely you formulate, the better prediction you get — not because AI 'understood' you, but because you narrowed the space of possible responses.
What this means for prompting
Knowing how the model works directly affects your prompting strategy. When you know the model predicts the next token, you understand why clear structure helps — it steers prediction in the right direction. When you know the model has no memory between conversations, you stop expecting it to 'remember' last week's chat. When you know about the 'lost in the middle' effect, you put key instructions at the beginning and end of your prompt.
Three rules that follow from this
First: be explicit, not implicit. The model won't guess what's in your head — it works only with what you write. Second: order matters. The model processes text left to right, token by token. Put important instructions first. Third: when the response isn't good, the problem is almost always in the prompt, not the model. Reformulate instead of getting frustrated.
Practice this scenario only with fictional or suitable public material without personal or confidential information. Do not upload actual messages, internal documents or client data; real use requires an approved tool and workflow. Give AI two versions of the same request: Version A: 'Write me something about productivity.' Version B: 'I'm a manager of a small remote team (5 people). Write me 5 specific tips to improve team productivity. Format each tip as: tip name in bold, 2 sentences of explanation, 1 concrete implementation example.' Compare the results. Notice how the structure of your prompt directly influences the structure of the response — because the model generates tokens to match the pattern you gave it.
Hint
Version B should produce a significantly more structured and usable response. The key is that you gave the model an output format — this works as a 'template' that the model follows token by token.
Practice this scenario only with fictional or suitable public material without personal or confidential information. Do not upload actual messages, internal documents or client data; real use requires an approved tool and workflow. Give AI the same task but with a key instruction in different positions: Version A: 'Write 5 energy-saving tips for homes. Respond as an energy consultant. Each tip max 2 sentences. Format: numbered list.' Version B: 'Each tip max 2 sentences. Write 5 energy-saving tips for homes. Format: numbered list. Respond as an energy consultant.' Compare: did AI respect the 2-sentence limit in both versions? Which version better follows all instructions?
Hint
Instructions at the beginning and end of a prompt typically have more influence. If response length is your top priority, put that constraint first.
Practice this scenario only with fictional or suitable public material without personal or confidential information. Do not upload actual messages, internal documents or client data; real use requires an approved tool and workflow. Start a conversation with AI and gradually extend it. In the first message, tell AI a specific fact: 'My favorite number is 42 and my name is Albatross.' Then have a conversation on any topic (10+ messages). At the end, ask: 'What is my favorite number? What is my name?' Can AI remember? Try the same with a longer conversation. At what point does AI start forgetting?
Hint
This exercise shows how the context window works in practice. For short conversations, AI remembers everything. For long ones (hundreds of messages), it may start forgetting information from the beginning — especially with smaller models.
Prompt Engineering — full course
- Language models generate text in tokens; internal reasoning and tools may complement this
- Token counts depend on tokenizer and language
- Check context limits for the specific model and product
- Generation parameters have different effects; not every model supports them
- State key instructions clearly and verify compliance
- A structured prompt helps but does not guarantee a correct response