How LLMs Work, and How to Ask So They Stop Guessing
A model predicts the next token from its context window and nothing else. That explains confident wrong answers and the fixes: put the source in the window, give it an out, and write the prompt as a spec that answers five questions.
Key takeaways
- A model predicts the next token from everything in its context window and keeps nothing between requests.
- When the true answer is not in the window, the model still produces a plausible one, just as fluently.
- Grounding, an out-clause, quotes and a separate check reduce invented answers, in that order of effect.
- A good prompt answers five questions: who, what, what the model cannot see, what shape, and how to tell it is right.
- When an answer disappoints, fix only the block that failed; "think step by step" and ALL-CAPS rules no longer help.
Contents
FAQ
Does the model remember my previous chats?
Only what the app puts back into the context: a memory feature, a project file, or the current conversation. The model itself keeps nothing between requests.
Why does it invent facts?
It produces the most plausible continuation. When the true answer is not in its context or training, a plausible-sounding one is still likely. Give it the source and allow it to say it does not know.
Is a longer prompt better?
A more specific one is. Cut adjectives like "clean" and "high-quality"; add facts like file names, versions, examples and the reason for the request.
Sources
Only you and the owner see your answer and rating. Send private feedback
Enjoyed it? Support fx-blog with a coffee.
Related posts
Your LLM Proxy Retries the Wrong Errors
What an LLM proxy has to decide on every failure: limits are per organization, which statuses to retry, why nothing is retried after the first streamed byte, and the headroom headers the API already sends.
Your LLM Demo Works. What Every Call Needs in Production
One timestamp in the system prompt and every call misses the cache. Pricing each call, making failures loud, logging per feature, and treating outside text as untrusted.
RAG That Works: Why Retrieval Matters More Than the Prompt
Most bad RAG answers are retrieval problems. How RAG works end to end, the three parts of the grounded prompt, how to measure retrieval alone, and when long context is enough.
Comments
Oldest firstNo comments yet. Start the conversation.
Type "The capital of France is" and a model scores every possible next token, a chunk of about three-quarters of a word: " Paris" at 0.92, " a" at 0.03, " located" at 0.01. It appends the winner and scores again. That loop is the whole engine.
Now ask it for the login rate limit on your auth service. It returns the most plausible number, whether or not your config was ever in front of it.
I started the guide behind this series as a list of prompts, then rebuilt it as a practices guide: most AI failures at work come from the wrong task, the wrong context, output nobody verified, or an agent with too many permissions. So the series follows one change from input to output: rate limiting on
POST /api/login, five attempts per 15 minutes per IP.AI Practices for Engineers, in 6 parts:
It does not cover building AI features on the API.
The model sees one window, and nothing outside it
The context window is everything the model gets on one request: the tool's hidden system prompt, your rules files, attached files, the conversation so far, and your message.
Nothing persists between calls. A chat app that seems to remember you is re-sending your history.
Why it sounds sure when it's wrong
The model produces the most plausible continuation. When the true answer is not in the window, a plausible one still comes out, just as fluent. The guide puts it bluntly: fluency and accuracy are uncorrelated at the failure boundary. Its four fixes, most effective first:
A prompt is a spec: five questions
Ask for
write tests for the loginand you get a generic snippet in a framework you don't use. You asked for less than you meant.A good prompt answers five questions the model can't answer for itself:
LoginPagepage object, the spectest()per case, assertions on visible textThe line people leave out is the reason. "They guard the new rate limit" tells the model which case matters most:
Fix the block that failed, and drop the old tricks
When the answer still disappoints, don't start over. Fix only the block that failed.
Try it
The spec works. Tomorrow, in a new chat, you will type "TypeScript, page objects in tests/pages/LoginPage.ts, pnpm not npm" again, and the review prompt you paste on every diff. Where do those lines live so the model reads them every time? Part 2, Rules Files and a Prompt Library, moves them into the repo.
Read this with your AI