50 LLM Interview Questions and Answers
The questions that come up most in AI engineer and LLM engineer interviews, grouped the way interviews usually move: fundamentals, context and prompting, RAG, tools and agents, then production. All 50 are listed below, with model answers to six of them: each written to be said out loud in under a minute, with what the interviewer is checking and the follow-up to expect. The full set of answers comes as a free PDF.
50 questions · 6 sample answers · Updated
Get all 50 answers as a free PDFOn this page · 5 sections
Fundamentals
1. What happens, step by step, when you send a prompt to an LLM?
Sample answer
The API wraps my messages in the model's chat template, so system prompt, history and my message become one long sequence of text. That text is tokenized into IDs, each ID is looked up as an embedding vector, and the vectors go through a stack of transformer layers. At the last position the model outputs a logit for every token in its vocabulary, softmax turns those into probabilities, and a sampler picks one token. That token is appended and the whole thing runs again, one token at a time, until a stop token or the max-token limit. Processing the prompt is called prefill and it's why there's a pause before the first token; the token-by-token part is decode, which is what you see streaming. And the model keeps nothing between calls: anything it seems to remember was sent again in the context.
- What they’re checking:
- Whether you have a working mental model of tokenize, embed, transform, predict, sample and repeat, and know the model is stateless.
- Likely follow-up:
- Where in that pipeline does the randomness come from, and why does the response pause before it starts streaming?
- Avoid:
- Describing the model as looking things up in a database or remembering earlier conversations by itself.
2. What is a token, and why don't models use words?
- What they’re checking:
- Whether you understand the vocabulary-size versus sequence-length tradeoff and its practical effects on cost and model behavior.
- Likely follow-up:
- Why is a model bad at counting the letters in a word?
3. Why does the same sentence cost different amounts in different languages?
- What they’re checking:
- Whether you connect tokenizer training data to cost, latency and context limits for real users.
- Likely follow-up:
- How would you estimate the cost of a feature that serves five languages?
4. What is an embedding?
- What they’re checking:
- Whether you know embeddings are learned, compared by geometry, and model-specific.
- Likely follow-up:
- What happens to your index if you upgrade the embedding model?
5. Cosine similarity vs dot product: when does it matter?
- What they’re checking:
- Whether you know normalization makes them equivalent and that the real risk is a silent metric mismatch.
- Likely follow-up:
- Where else, besides the index, could the metric be set wrong?
6. What does attention do, in plain terms?
- What they’re checking:
- Whether you can explain query, key, value and content-based weighting without hiding behind jargon.
- Likely follow-up:
- Why does long context get expensive, and what does the KV cache save?
7. What are logits, and what does temperature change?
- What they’re checking:
- Whether you know temperature reshapes the distribution without making the model smarter or more correct.
- Likely follow-up:
- How do top-k and top-p differ from temperature?
8. Pretraining vs post-training: what does each give you?
- What they’re checking:
- Whether you can separate where knowledge comes from and where assistant behavior comes from.
- Likely follow-up:
- Why does a model have a knowledge cutoff, and how do you work around it?
9. Why do models hallucinate, and why don't they just say "I don't know"?
Sample answer
A model generates the most plausible continuation from patterns in its weights, and nothing in that process checks the result against the truth. Common facts are stored well; rare ones are blurry or missing, but a confident, fluent answer is still a high-probability continuation, so you get a real-looking citation for a paper that doesn't exist. As for "I don't know," two reasons. The model often can't tell what it doesn't know, because it has no reliable internal signal tied to correctness. And training and evaluation have tended to reward a guess over an abstention, the way a test with no penalty for wrong answers rewards always answering. In an application I reduce it by grounding answers in retrieved sources, telling the model it may say the answer isn't there, and checking important claims in code or with a human.
- What they’re checking:
- Whether you understand the mechanism and have practical mitigations instead of hoping a bigger model fixes it.
- Likely follow-up:
- How would you detect hallucinations in production?
- Avoid:
- Saying RAG or a newer model eliminates hallucinations.
10. What do reasoning models do differently, and when are they worth the cost?
- What they’re checking:
- Whether you see reasoning as a cost and latency tradeoff and can name tasks on each side.
- Likely follow-up:
- If the visible reasoning looks correct, does that mean the answer is correct?
Context and prompting
11. What consumes a context window besides the user's message?
- What they’re checking:
- Whether you think of context as a shared budget and know which parts grow silently.
- Likely follow-up:
- The agent's context keeps overflowing after 20 steps. What do you change?
12. Why can a model miss information that's inside its window?
- What they’re checking:
- Whether you know the difference between maximum context and effective context.
- Likely follow-up:
- How would you measure effective context length for your application?
13. Long context vs RAG: how do you choose?
Sample answer
If the documents fit comfortably, don't change often, and every user may see all of them, I'd put them straight in the prompt. It's simpler, and there's no retrieval step that can miss. RAG wins when the corpus is bigger than the window, when it changes often, when different users have different permissions, or when cost matters, because a stuffed prompt is billed on every request while retrieval only sends a slice. Prompt caching narrows the cost gap but doesn't remove it. Recall quality also favors a few well-chosen passages over a huge context full of distractors. For example, a short internal wiki for one small team: paste it in. A support knowledge base with tens of thousands of articles and per-plan visibility: RAG. In between, I'd build the simple version first and compare both on real queries.
- What they’re checking:
- Whether you decide on scale, cost, freshness and permissions instead of picking a side by habit.
- Likely follow-up:
- How does prompt caching change this decision?
- Avoid:
- Saying long context made RAG obsolete, or building RAG for a few pages of text.
14. Context engineering vs prompt engineering: what's the difference?
- What they’re checking:
- Whether you see production context as software with versions, budgets and tests.
- Likely follow-up:
- How would you version and test a context pipeline?
15. Why isn't "respond in JSON" in the prompt enough?
- What they’re checking:
- Whether you know the difference between asking for a format and enforcing it.
- Likely follow-up:
- What can still go wrong once the output is schema-valid?
16. How do structured outputs work, and what can still go wrong?
- What they’re checking:
- Whether you separate syntactic validity from semantic and business correctness.
- Likely follow-up:
- How would you design retries when validation fails?
17. When do few-shot examples help, and when do they hurt?
- What they’re checking:
- Whether you choose examples on purpose and know the side effects.
- Likely follow-up:
- How would you choose which examples to include?
RAG
18. What problem does RAG solve, and what doesn't it solve?
- What they’re checking:
- Whether you can match RAG to knowledge gaps and rule it out for capability gaps.
- Likely follow-up:
- When is RAG unnecessary?
19. Walk me through a basic RAG pipeline.
- What they’re checking:
- Whether you know both phases and where filtering, reranking and citations fit.
- Likely follow-up:
- Which stage fails most often in practice?
20. RAG vs fine-tuning: when do you pick each?
- What they’re checking:
- Whether you can explain why fine-tuning is the wrong tool for factual knowledge.
- Likely follow-up:
- When would you fine-tune instead of improving the prompt?
21. How do you choose a chunking strategy?
- What they’re checking:
- Whether you choose chunking from content and queries and verify it with retrieval metrics.
- Likely follow-up:
- How much overlap would you use between chunks, and why?
22. Why not embed whole documents? Why not single sentences?
- What they’re checking:
- Whether you understand both failure modes and the self-contained, single-topic target.
- Likely follow-up:
- When would you retrieve a small chunk but send a larger surrounding section to the model?
23. Keyword vs semantic vs hybrid search: when do you use each?
- What they’re checking:
- Whether you know each method's blind spot and how the results get merged.
- Likely follow-up:
- How does reciprocal rank fusion work?
24. What is reranking, and where does it go in the pipeline?
- What they’re checking:
- Whether you understand the recall-then-precision funnel and why cross-encoders are only used on a shortlist.
- Likely follow-up:
- How would you measure whether adding a reranker helped?
25. How do you evaluate retrieval separately from generation?
- What they’re checking:
- Whether you can attribute failures to retrieval or generation with concrete metrics.
- Likely follow-up:
- Where do the labeled queries come from if you're starting from nothing?
26. Your RAG bot gives a wrong answer. How do you debug it?
Sample answer
First I read the passages that were retrieved for that exact query. That one step splits the problem in half. If the right evidence isn't there, I go upstream: is the answer in the corpus at all, was the document parsed cleanly, did chunking split it, does searching with the gold chunk's own text find it, did a permission filter drop it, did it rank too low, or did the context budget cut it. If the evidence is there, I go downstream: was it truncated or out of order in the prompt, or did the model misread it or ignore the instruction to abstain. In my experience most wrong answers come from retrieval, not the model. Once I find the stage, I fix it and add the query to the eval set so it can't silently regress.
- What they’re checking:
- Whether you debug stage by stage starting from the retrieved evidence instead of rewriting the prompt.
- Likely follow-up:
- What tooling would you build so this takes minutes instead of hours?
- Avoid:
- Starting by tweaking the system prompt or switching models.
Tools and agents
27. What is tool calling, and who executes the tool?
- What they’re checking:
- Whether you know the model only proposes calls and the application owns execution and safety.
- Likely follow-up:
- Walk me through the full loop when the model calls two tools in one turn.
28. What makes a good tool definition?
- What they’re checking:
- Whether you treat tool design as both prompt design and security design.
- Likely follow-up:
- The model keeps picking the wrong one of two similar tools. What do you do?
29. Why must tool arguments be validated?
- What they’re checking:
- Whether you treat the model as an untrusted client of your tools.
- Likely follow-up:
- Where should authorization happen: in the prompt, in the tool, or somewhere else?
30. What makes a system an agent rather than a workflow?
Sample answer
Who controls the sequence of steps. In a workflow, code decides the steps in advance; the model may do work inside a step, like classify or draft, but it doesn't choose what happens next. In an agent, the model runs a loop: it looks at the current state, picks the next action from the available tools, sees the result, and decides again until it reaches a stop condition. The path is discovered as it goes. It's more of a spectrum: a single call, a call with tools, a workflow with model steps, a fully model-directed loop. For example, checking every invoice against its contract with a model call per invoice is a workflow. "Find out why the build broke and fix it" is an agent task, because the next thing to inspect depends on what the last step found.
- What they’re checking:
- Whether you define agents by control flow instead of by marketing labels.
- Likely follow-up:
- How would you combine the two in one system?
31. When should you not use an agent?
- What they’re checking:
- Whether you default to the simplest design and can justify when autonomy is worth it.
- Likely follow-up:
- How would you prove an agent is better than a simpler pipeline?
32. How does an agent know when to stop?
- What they’re checking:
- Whether you design explicit terminal states and enforce budgets in code.
- Likely follow-up:
- How do you detect that an agent is stuck repeating itself?
33. Agent state vs agent memory: what's the difference?
- What they’re checking:
- Whether you can separate run-scoped data from cross-run data and know why they're built differently.
- Likely follow-up:
- What should an agent never write to memory automatically?
34. What is MCP, and what problem does it solve?
- What they’re checking:
- Whether you understand MCP as integration plumbing and know its limits.
- Likely follow-up:
- What are the main security risks of connecting a third-party MCP server?
35. MCP tools vs resources vs prompts?
- What they’re checking:
- Whether you know the three primitives and connect each one to who controls it.
- Likely follow-up:
- Can a resource carry a prompt injection? What do you do about it?
36. How would you limit what an agent is allowed to do?
- What they’re checking:
- Whether you put limits in enforced infrastructure instead of instructions in the prompt.
- Likely follow-up:
- Which actions would you require approval for, and how do you avoid approval fatigue?
Production
37. How do you test a system whose outputs are nondeterministic?
- What they’re checking:
- Whether you separate deterministic code from model output and use the right test for each.
- Likely follow-up:
- When would you use snapshot tests in an AI system?
38. How do you build an eval dataset from scratch?
- What they’re checking:
- Whether you know where good cases come from and that labels and slices make them usable.
- Likely follow-up:
- How do you stop the team from overfitting the prompt to the eval set?
39. LLM-as-judge: when is it trustworthy, and how do you check it?
- What they’re checking:
- Whether you know the judge's biases and that its trust comes from measured agreement with humans.
- Likely follow-up:
- The judge agrees with humans overall but not on one category. What do you do?
40. What is prompt injection, and why can't a better system prompt fix it?
Sample answer
Prompt injection is text from an untrusted source, like a web page, an email or a tool result, that contains instructions the model then follows. The developer's instructions and the attacker's text arrive through the same channel: tokens in one context window. The model only has a learned tendency to weight system instructions higher, so it can't reliably tell them apart. Delimiters, marking untrusted spans, and instruction-hierarchy training make attacks harder, and I'd use all of them, but they lower how often an attack works without ruling it out. A line like "never follow instructions in documents" loses to a document that claims the user changed their instructions, because the model can't verify that claim. So the real defense is architecture that limits damage: least privilege, validated tool calls, approvals, and no outbound path for secrets.
- What they’re checking:
- Whether you see injection as an architecture problem and plan for it succeeding.
- Likely follow-up:
- How would you threat-model an email assistant against injection?
- Avoid:
- Claiming a stronger system prompt or a classifier solves it.
41. How can an agent leak data, and how do you prevent it?
- What they’re checking:
- Whether you can name concrete exfiltration channels and break the combination that enables them.
- Likely follow-up:
- How does a markdown image leak data without any tool call?
42. TTFT vs inter-token latency: what makes each slow?
- What they’re checking:
- Whether you can split latency into components with different causes and fixes.
- Likely follow-up:
- Users say it feels slow but p50 total latency looks fine. Where do you look?
43. Give me five ways to cut latency in an LLM app.
- What they’re checking:
- Whether you know concrete levers and protect quality while using them.
- Likely follow-up:
- Which of those can change answer quality, and how would you check?
44. Exact, semantic and provider prompt caching: what are the tradeoffs?
- What they’re checking:
- Whether you know which caches can serve wrong answers and which can't.
- Likely follow-up:
- How would you structure a prompt to get more prompt-cache hits?
45. How do you design a cache key for an LLM response?
- What they’re checking:
- Whether you understand that under-keying is a correctness bug and over-keying is only inefficiency.
- Likely follow-up:
- How does multi-tenancy affect what's safe to cache?
46. What would you log and trace in production?
- What they’re checking:
- Whether your logging can answer "what changed and why did this request fail" without leaking user data.
- Likely follow-up:
- How would you detect quality drift with no ground-truth labels?
47. Estimate the monthly cost of this feature (walk me through it).
- What they’re checking:
- Whether you can do the arithmetic cleanly and know what per-token math leaves out.
- Likely follow-up:
- What would you change first if that number came in 5x over budget?
48. Closed vs open-weight models: when would you self-host?
- What they’re checking:
- Whether you can name concrete reasons to self-host and count the operational cost.
- Likely follow-up:
- How would you work out the break-even volume for self-hosting?
49. How do you handle user PII sent to a model provider?
- What they’re checking:
- Whether you treat privacy as data flow you control, starting with what you send.
- Likely follow-up:
- How do you handle a user's deletion request when their data is in logs and a vector store?
50. How do you review AI-generated code before merging?
- What they’re checking:
- Whether you review against intent and know the specific failure modes of generated code.
- Likely follow-up:
- Can a model review its own generated code?
How to use these questions
- Say each answer out loud. Reading an answer and saying one are different skills. Aim for 45 to 75 seconds and time yourself.
- Lead with the answer. Your first sentence should answer the question; the reasoning and example come after.
- Swap in your own example. Replace the example in each answer with one from your own work: a RAG system you built, an agent that misbehaved, a cost you had to cut. Interviewers follow up on what you’ve done.
- Practice the follow-up. Answer the follow-up question without looking, then check it against the full answer.
- Learn the red flags. If you catch yourself giving the weak answer, go back over that subject before the interview.
More interview questions
- RAG interview questions Retrieval, chunking, evaluation, debugging and securing RAG.
- Agentic AI interview questions Agent loops, tools, state, memory and permissions.
- AI engineer interview questions Fundamentals, building, production and your projects.
- Prompt engineering interview questions Prompts, context engineering, structured outputs, injection.
- LLM evaluation interview questions Eval datasets, graders, LLM-as-judge and monitoring.
- MCP interview questions Model Context Protocol: hosts, clients, servers and security.