LLM Engineer interview questions
100 real questions with model answers and explanations for Junior candidates.
See a LLM Engineer resume example →Practice with flashcards
Spaced repetition · Hunter Pass
Questions
An LLM repeatedly predicts a probability distribution for the next token from the tokens already in its context.
- A decoding rule selects one token from that distribution and appends it to the sequence.
- The expanded sequence is fed back into the model until a stop condition or output limit is reached.
- The model generates statistically likely continuations, not answers retrieved from a built-in factual database.
Why interviewers ask this: The interviewer checks whether the candidate understands generation as iterative next-token prediction.
A transformer is a neural-network architecture that processes token representations through attention and feed-forward layers.
- Attention lets each token combine information from relevant tokens in the available sequence.
- Feed-forward blocks transform each token representation after attention has mixed context.
- Residual connections and normalization help many layers train and pass information reliably.
Why interviewers ask this: A strong answer names the major building blocks without reducing a transformer to attention alone.
Tokenization converts text into integer token IDs from the model's fixed vocabulary.
- A token may represent a whole word, part of a word, punctuation, whitespace, or a byte sequence.
- The model consumes IDs and maps them to learned vector representations before transformer layers process them.
- Different model families can tokenize the same text differently, so token counts are tokenizer-specific.
Why interviewers ask this: The interviewer evaluates whether the candidate distinguishes model tokens from words and characters.
Token counts determine how much input fits, how much output remains available, and often how an API request is priced.
- The prompt, conversation history, retrieved context, and generated answer share the model's context budget.
- Long inputs increase computation and can dilute useful evidence even when they fit technically.
- Counts should use the tokenizer of the selected model rather than a word-count estimate.
Why interviewers ask this: A strong answer connects tokens to context capacity, latency, cost, and model-specific measurement.
The context window is the maximum token sequence the model can consider for one generation request.
- It includes instructions, examples, user input, retrieved documents, tool results, history, and usually the generated continuation.
- Content outside the supplied window is not remembered automatically by the model.
- A larger window increases capacity but does not guarantee that every detail will be used accurately.
Why interviewers ask this: The interviewer checks whether context is understood as bounded request input rather than permanent memory.
Attention computes how strongly one token representation should use information from other token representations in the sequence.
- Queries are compared with keys to produce weights, and those weights combine the corresponding values.
- Different attention heads can learn different relationships such as syntax, references, or local patterns.
- Attention weights are intermediate computations and should not be treated as a complete explanation of model reasoning.
Why interviewers ask this: A strong answer explains information mixing while avoiding the myth that attention weights fully explain a model.
Causal self-attention lets each position attend only to itself and earlier positions, not future tokens.
- A causal mask enforces this left-to-right information flow during training and generation.
- The model can train on many next-token targets in parallel even though inference emits tokens sequentially.
- Models such as Llama and Qwen use decoder-only transformer designs for autoregressive generation.
Why interviewers ask this: The interviewer evaluates whether the candidate connects masking with next-token generation.
Attention alone does not encode token order, so the model needs positional information to distinguish differently ordered sequences.
- Position embeddings or rotary position encodings add order-related signals to token representations.
- This lets the model distinguish meanings where the same tokens appear in a different order.
- The positional method also influences how a model behaves near and beyond its trained context lengths.
Why interviewers ask this: A strong answer explains why sequence order is not provided by token identity alone.
Pretraining teaches a model broad language patterns by optimizing next-token prediction over a large text corpus.
- The model adjusts its parameters to reduce prediction loss across many examples.
- Pretraining can produce broad capabilities but does not by itself make the model follow user instructions reliably.
- Data quality, mixture, scale, and training objective all shape the resulting base model.
Why interviewers ask this: The interviewer checks whether the candidate distinguishes general language pretraining from later alignment.
A parameter is a learned numeric weight that contributes to the transformations performed by the network.
- Training updates parameters to reduce the objective on training examples.
- Parameter count is one indicator of model capacity and compute cost, not a direct measure of answer quality.
- Facts are distributed across many weights rather than stored as readable records with exact source links.
Why interviewers ask this: A strong answer separates learned weights from database records and avoids equating size with quality.
A base model predicts text continuations, an instruct model is tuned to follow tasks, and a chat model is adapted to structured multi-turn roles.
- Base models often need completion-style prompting and may continue the prompt instead of answering it.
- Instruct models learn response patterns from instruction and answer examples.
- Chat models expect a model-specific template for system, user, and assistant messages.
Why interviewers ask this: The interviewer evaluates whether the candidate matches prompting format to the model's training.
Instruction tuning fine-tunes a pretrained model on examples that pair tasks or conversations with desired responses.
- It teaches the model to interpret requests and produce response formats more useful than raw continuation.
- The examples can cover question answering, summarization, extraction, dialogue, and refusal behavior.
- Instruction tuning improves behavior but does not guarantee factual accuracy or safety in every prompt.
Why interviewers ask this: A strong answer describes the data and behavioral goal of instruction tuning without overstating its guarantees.
Preference alignment trains a model to favor responses judged better according to human or synthetic preference data.
- Methods may learn a reward or preference signal and optimize the model toward preferred outputs.
- Alignment can improve helpfulness, style, and safety after supervised instruction tuning.
- It can also introduce biases from raters and objectives, so preferred behavior is not the same as objective truth.
Why interviewers ask this: The interviewer checks whether the candidate understands alignment as optimization against preferences rather than factual verification.
A hallucination is fluent output that is unsupported, fabricated, or inconsistent with the available evidence.
- Next-token training rewards plausible continuation and does not guarantee a fact-check before every claim.
- Hallucinations can affect facts, citations, calculations, tool results, and claims about provided context.
- Grounding, retrieval, tools, constraints, and evaluation can reduce risk but cannot remove it completely.
Why interviewers ask this: A strong answer explains both the symptom and why fluent generation can produce unsupported claims.
A text embedding is a dense numeric vector designed to represent useful semantic properties of text.
- An embedding model maps a query, sentence, or document into a fixed-length vector.
- Similar meanings often produce nearby vectors according to the model's training objective.
- The vector is useful for retrieval, clustering, classification, and deduplication, but it is not human-readable text.
Why interviewers ask this: The interviewer evaluates whether embeddings are understood as learned representations rather than compressed documents.
Semantic similarity is estimated by comparing embedding vectors with a metric such as cosine similarity or dot product.
- The query and candidate text must be encoded with the expected input format of a compatible embedding model.
- A higher score generally means closer representation under that model, not guaranteed relevance for every business task.
- Similarity thresholds and rankings need evaluation on domain examples rather than universal constants.
Why interviewers ask this: A strong answer connects vector comparison to model-specific and task-specific relevance.
Stored documents and queries must be represented in the same compatible vector space for their similarity scores to be meaningful.
- Changing the embedding model usually requires re-embedding the indexed corpus.
- Some models use different query and passage prefixes or encoders while still producing a deliberately shared space.
- Vector dimensions alone do not prove compatibility because two models can have equal dimensions and unrelated geometry.
Why interviewers ask this: The interviewer checks whether the candidate understands embedding-space compatibility beyond matching array length.
Embedding dimension is the number of numeric components in each vector and affects storage, index memory, and computation.
- Higher dimension can represent more features but does not automatically produce better retrieval.
- The dimension is fixed by the selected embedding model and must match the vector index schema.
- Model quality should be compared on retrieval evaluation, not selected by dimension alone.
Why interviewers ask this: A strong answer recognizes operational cost while rejecting dimension as a standalone quality metric.
A vector database stores embeddings and retrieves nearby vectors efficiently, usually together with source text and metadata.
- Approximate nearest-neighbor indexes trade a small amount of recall for faster search at scale.
- Metadata filters can restrict candidates by tenant, language, date, or document type.
- The database finds similar records; it does not itself generate an answer or guarantee relevance.
Why interviewers ask this: The interviewer evaluates whether the candidate understands the retrieval role and limits of a vector database.
Metadata filters enforce known constraints before or during similarity search so semantically close but invalid records are excluded.
- Typical filters include access scope, tenant, locale, product, time range, and publication status.
- Filtering can improve relevance and prevent cross-tenant or unauthorized retrieval.
- Metadata needs consistent indexing and governance because missing or incorrect fields silently remove or expose candidates.
Why interviewers ask this: A strong answer connects metadata to both relevance and access boundaries.
Locked questions
- 21
What are the main stages of retrieval-augmented generation?
retrieval - 22
What can RAG improve, and what does it not solve automatically?
rag - 23
What is chunking in a RAG pipeline?
ragchunkingci-cd - 24
Why is chunk overlap used, and what is its trade-off?
- 25
What does top-k mean in retrieval?
retrieval - 26
How do sparse and dense retrieval differ?
retrieval - 27
What is hybrid search in RAG?
rag - 28
What is reranking in a RAG pipeline?
ragrerankingci-cd - 29
Why do grounded answers often include citations?
groundednesscitations - 30
What is the difference between zero-shot and few-shot prompting?
prompting - 31
What is the role of a system prompt in a chat model?
promptingsystem-design - 32
Why should prompts separate instructions, data, and examples clearly?
prompting - 33
What is a prompt template?
prompting - 34
How do prompt engineering, RAG, and fine-tuning solve different problems?
ragpromptingfine-tuning - 35
What does fine-tuning an LLM mean?
fine-tuningllm - 36
What is LoRA in LLM fine-tuning?
fine-tuningllm - 37
What does temperature control during LLM decoding?
decodingllm - 38
How do top-k and top-p sampling work?
sampling - 39
How do greedy decoding and sampling differ?
decodingsampling - 40
Does setting a random seed make LLM output fully deterministic?
llm - 41
What do maximum output tokens and stop sequences do?
tokens - 42
What is LangChain used for?
langchain - 43
What is LlamaIndex used for?
llamaindex - 44
How do schema-constrained generation tools such as Outlines and Instructor help?
schema - 45
How do vLLM, TGI, Ollama, and llama.cpp differ at a high level?
- 46
What are the basic trade-offs between a hosted LLM API and an open-weight model?
llmapi - 47
What is offline evaluation for an LLM application?
llmllm-eval - 48
What metrics can evaluate generated answers?
llm-evaldecision-makingmonitoring - 49
How is retrieval quality evaluated in RAG?
ragretrievaldecision-making - 50
What makes an LLM evaluation dataset trustworthy?
llmllm-eval - 51
How would you build a basic RAG feature over a collection of product documents?
rag - 52
How would you choose chunk boundaries for a RAG knowledge base?
rag - 53
When would you add overlap between RAG chunks?
rag - 54
What metadata would you store with document embeddings?
nlpembeddings - 55
How would you choose an embedding model for semantic search?
nlpembeddingsretrieval - 56
How would you choose between cosine similarity, dot product, and Euclidean distance for embeddings?
nlpembeddings - 57
How would you store and search embeddings for a small first version of a RAG feature?
nlpragembeddings - 58
How would you choose top-k for RAG retrieval?
ragretrieval - 59
How would you combine keyword and embedding search in a RAG feature?
nlpragembeddings - 60
When would you add a reranker to a RAG pipeline?
ragrerankingci-cd - 61
How would you add reliable citations to a RAG answer?
ragcitations - 62
How would you make a RAG assistant abstain when the documents do not contain an answer?
rag - 63
How would you improve retrieval for vague or conversational user questions?
retrieval - 64
How would you handle conversation history in a multi-turn RAG assistant?
rag - 65
How would you structure a prompt for a document-grounded assistant?
groundednessprompting - 66
When would you add few-shot examples to an LLM prompt?
promptingllm - 67
How would you improve a prompt that produces inconsistent answers?
prompting - 68
How would you prevent retrieved documents from overriding system instructions?
system-designoop - 69
How would you make an LLM API return data that matches a Python model?
llmapipython - 70
When would you use constrained generation with Outlines or Guidance?
- 71
How would you reduce hallucinations in a question-answering feature?
hallucination - 72
How would you evaluate whether an LLM answer is factually grounded in provided context?
groundednessllmdecision-making - 73
How would you create a useful evaluation dataset for an LLM feature?
llmllm-eval - 74
How would you evaluate the retrieval stage of a RAG system?
ragretrievalsystem-design - 75
How would you evaluate a RAG feature end to end?
ragdecision-makingllm-eval - 76
How would you write a human evaluation rubric for assistant answers?
llm-eval - 77
How would you use an LLM as a judge without trusting it blindly?
llm - 78
How would you set up regression evaluations for prompt or model changes?
promptingllm-eval - 79
What online signals would you collect after launching an LLM feature?
llm - 80
How would you integrate OpenAI API or Anthropic API into a Python service?
python - 81
How would you handle timeouts and transient failures from an LLM API?
llmapiresilience - 82
How would you handle provider rate limits in an LLM application?
llmrate-limiting - 83
How would you budget tokens for a prompt with retrieval and chat history?
retrievalpromptingtokens - 84
How would you shorten context when an LLM request exceeds the model window?
llm - 85
How would you stream an LLM response through a FastAPI endpoint?
llmendpointsframeworks - 86
How would you choose between a hosted API and a locally served Llama 3.1 or Qwen 2.5 model?
api - 87
How would you expose a local model through vLLM for a Python application?
python - 88
How would you use Ollama or llama.cpp during local LLM prototyping?
llmprototypes - 89
What would you cache in an LLM application?
llmcaching - 90
How would you track and reduce LLM API cost?
llmapi - 91
How would you prevent personal data from being sent unnecessarily to an LLM provider?
llmdiscovery - 92
How would you add basic protection against prompt injection in a RAG assistant?
ragpromptinginjection - 93
How would you add output guardrails for a user-facing LLM response?
llmguardrailsllm-safety - 94
How would you validate LLM-generated tool calls before execution?
llmvalidation - 95
How would you protect LLM provider API keys in development and deployment?
llmapideployment - 96
What would you trace for an LLM request using LangSmith, Helicone, or custom telemetry?
llm - 97
How would you handle a structured LLM response that fails validation?
llmvalidation - 98
How would you change embedding models without corrupting search results?
nlpembeddings - 99
How would you keep a RAG index synchronized with changing and deleted source documents?
ragindexes - 100
What would you verify before launching a first LLM-powered RAG feature?
ragllm