AI and LLMs Middle cheat sheet: interview answers

Every question of this level with its correct answer and explanation, on one page for a quick review before the interview.

  1. 1. What is "context engineering" in LLM apps?

    Correct answer: Choosing what information goes into the context for each step

    Beyond the prompt wording, results depend on which documents, history, tool results and instructions the model sees, and in what order.

  2. 2. Why is chunk overlap often used when splitting documents for RAG?

    Correct answer: So facts on chunk borders aren't cut in half

    A sentence split between two chunks may never be retrieved whole. A small overlap keeps context together at the cost of some duplication.

  3. 3. What is hybrid search in RAG?

    Correct answer: Combining keyword search like BM25 with vector search

    Vectors catch meaning; keywords catch exact terms like product codes and names. Combining them often improves retrieval.

  4. 4. What does a reranker do in a retrieval pipeline?

    Correct answer: Reorders retrieved candidates by relevance with a stronger model

    A fast first stage fetches, say, 50 chunks; a cross-encoder reranker picks the best 5 for the prompt, improving precision.

  5. 5. What does recall@k measure for a retriever?

    Correct answer: How often the relevant chunk is among the top k results

    If the right passage isn't retrieved, the model can't use it. Retrieval quality is measured separately from answer quality.

  6. 6. Which RAG metric checks whether the answer's claims are supported by the retrieved context?

    Correct answer: Faithfulness

    Faithfulness catches answers that add facts the sources don't contain. Answer relevance checks whether it actually addresses the question.

  7. 7. Why must a RAG system filter documents by user permissions?

    Correct answer: Otherwise users can get answers drawn from documents they can't access

    Access control belongs in retrieval, using metadata filters per user or tenant. A prompt instruction is not a security boundary.

  8. 8. What happens to an existing vector index if you switch to a new embedding model?

    Correct answer: It must be rebuilt; vectors from different models don't mix

    Each embedding model has its own vector space and often a different dimension. Re-embedding is part of the migration plan.

  9. 9. Which similarity measure is most common for comparing text embeddings?

    Correct answer: Cosine similarity

    Cosine similarity compares direction, not length, of vectors. Many models return normalized vectors, so dot product gives the same ranking.

  10. 10. What makes a tool definition easy for a model to use correctly?

    Correct answer: A clear name, a precise description and a strict input schema

    Models choose tools from their descriptions. Ambiguous tools get called at the wrong time or with wrong arguments.

  11. 11. A tool call fails with an error. What should the app usually send back to the model?

    Correct answer: A clear error result, so the model can retry or change approach

    Good error messages ("date must be YYYY-MM-DD") let the model fix its call. Hiding errors leads to confident wrong answers.

  12. 12. Why set a maximum number of steps for an agent loop?

    Correct answer: To stop runaway loops that waste tokens or repeat actions

    Agents can get stuck retrying the same tool. Step and budget limits, plus clear stop conditions, keep costs bounded.

  13. 13. When is a fixed workflow better than an autonomous agent?

    Correct answer: When the steps are known in advance and predictability matters

    Prompt chains and routing are cheaper, faster and easier to test. Agents fit tasks where the path can't be planned upfront.

  14. 14. What is prompt chaining?

    Correct answer: Splitting a task into steps where each LLM call uses the previous output

    For example: outline, then check the outline, then write. Checks between steps catch problems early.

  15. 15. What is the routing pattern in LLM workflows?

    Correct answer: Classifying input and sending it to a specialised prompt

    Simple questions can go to a small model, refunds to a refund flow, so each path is tuned and cheaper.

  16. 16. What is the evaluator-optimizer pattern?

    Correct answer: One model generates, another critiques, and the loop repeats

    It works when clear criteria exist, such as translation quality or code passing tests.

  17. 17. What three main things can an MCP server expose?

    Correct answer: Tools, resources and prompts

    Tools are actions, resources are readable data like files, and prompts are reusable templates the client can offer to users.

  18. 18. Why validate structured output with a schema library like Zod even when the model was asked for JSON?

    Correct answer: Output can still be malformed or have wrong types

    Validate, and on failure retry with the error message or fall back. Never pass unvalidated model output into code paths that trust it.

  19. 19. What is insecure output handling in LLM apps?

    Correct answer: Using model output unchecked, e.g. rendering it as HTML

    Rendering output with innerHTML can cause XSS; passing it to a shell or SQL can cause injection. Treat it like user input.

  20. 20. What is "excessive agency" in the OWASP LLM Top 10?

    Correct answer: Giving an LLM too many tools, permissions or autonomy

    If an injected prompt can make the agent send emails or delete data, the damage is large. Limit tools, scopes and require confirmation.

  21. 21. Why shouldn't secrets be placed in a system prompt?

    Correct answer: System prompts can leak through clever user questions

    Assume users can extract the system prompt. Keys and internal URLs belong in server code, not in text the model sees.

  22. 22. How can you reduce the impact of prompt injection in an agent that reads web pages?

    Correct answer: Limit tools, require confirmation for actions, treat page content as untrusted

    No prompt fully prevents injection. Defences are architectural: privilege separation, confirmations and output checks.

  23. 23. Which judge bias makes it prefer the first of two answers shown?

    Correct answer: Position bias

    Swap the order and average, or judge each answer alone against a rubric. Other known biases are verbosity and self-preference.

  24. 24. How do you make an LLM judge trustworthy?

    Correct answer: Calibrate it against human labels and use a clear rubric

    Measure agreement with human ratings on a sample. Specific rubrics ("mentions refund period, no invented fees") beat vague "rate quality".

  25. 25. What is pairwise evaluation?

    Correct answer: Showing two outputs and asking which is better for the criteria

    Comparisons are often easier to judge consistently than absolute scores, useful when testing a new prompt against the current one.

  26. 26. How should an LLM eval suite be used in CI?

    Correct answer: Run it on prompt or model changes and fail on score drops

    Thresholds per metric make prompt edits safe, like unit tests for code. Keep a fast subset for every PR and a full run nightly.

  27. 27. Why run each eval case several times?

    Correct answer: Outputs vary, so pass rates show reliability better than one sample

    A case passing 3 of 5 times is flaky in production too. Track variance, not just averages.

  28. 28. How do you unit-test code that calls an LLM without paying for each run?

    Correct answer: Mock the model client with recorded or fake responses

    Code around the model (parsing, retries, tool execution) can be tested deterministically. Separate evals test the model's quality.

  29. 29. What is a risk of using model-generated synthetic test data only?

    Correct answer: It can miss real user language and edge cases

    Synthetic cases are a fast start. Mix in real, anonymized queries and known failures to keep evals realistic.

  30. 30. How should multi-turn chatbot behaviour be tested?

    Correct answer: Scripted conversations checking context, memory and topic shifts

    Bugs show up in turn five: forgetting a constraint, contradicting itself, or being steered off-topic gradually.

  31. 31. Why is snapshot testing of exact LLM outputs usually a poor fit?

    Correct answer: Outputs change slightly between runs, causing noisy failures

    Check properties, schemas or judged criteria instead. Exact snapshots can work for deterministic code around the model.

  32. 32. What is a semantic cache for LLM calls, and its main risk?

    Correct answer: Reusing answers for similar queries; it may return wrong cached answers

    "Cancel my order" and "Can I cancel an order?" are similar but may need different answers. Thresholds and scoping are critical.

  33. 33. Which technique lowers cost for many requests with the same long instructions?

    Correct answer: Prompt caching of the shared prefix

    Put stable content (instructions, documents) first and variable content last so the prefix can be cached.

  34. 34. What is model routing for cost control?

    Correct answer: Sending easy requests to a cheaper model and hard ones to a stronger one

    A classifier or rules decide. Evals confirm the cheap path is good enough for the cases sent to it.

  35. 35. Why add a fallback provider or model for an AI feature?

    Correct answer: An outage at one provider shouldn't take the feature down

    Fallbacks need their own evals, since a different model may format or behave differently.

  36. 36. What does time to first token (TTFT) measure?

    Correct answer: How quickly the first output token arrives

    TTFT drives perceived speed in chat. Long prompts, large models and cold caches increase it.

  37. 37. What is the "lost in the middle" effect?

    Correct answer: Models can miss information placed in the middle of long contexts

    Put key instructions and the most relevant documents near the start or end, and keep contexts focused.

  38. 38. Why prefer answers with citations in a RAG product?

    Correct answer: They make answers verifiable and help tests check grounding

    Tests can check each citation points to a passage that supports the claim, a strong check against hallucination.

  39. 39. What is sensitive information disclosure in LLM apps?

    Correct answer: The model revealing personal, secret or internal data

    It can come from training data, RAG over unprotected documents or the system prompt. Redaction and access control reduce it.

  40. 40. How can personal data be kept out of LLM requests?

    Correct answer: Detect and redact or pseudonymize it before sending

    Replace names and IDs with placeholders, then restore them in the response if needed. Logs need the same care.

  41. 41. What should production monitoring of an AI feature include?

    Correct answer: Quality, feedback, cost, latency and errors

    Thumbs up/down, regeneration rate, escalations to humans and judge scores on samples show quality drifting before complaints arrive.

  42. 42. How do you A/B test two prompts in production safely?

    Correct answer: Split traffic, measure agreed metrics and run offline evals first

    Offline evals catch obvious regressions; online metrics like resolution rate and feedback show real impact.

  43. 43. What is the trade-off of self-hosting open-weight models versus using an API?

    Correct answer: More control and privacy, but you run the infrastructure

    Self-hosting needs GPUs, monitoring and updates. APIs are simpler but send data to a provider under its terms.

  44. 44. What is quantization of a model?

    Correct answer: Storing weights with fewer bits to save memory and speed up inference

    8-bit or 4-bit weights fit larger models on smaller GPUs, often with a small quality loss that evals should measure.

  45. 45. What is model distillation?

    Correct answer: Training a smaller model to imitate a larger one's outputs

    A distilled model can be much cheaper for a specific task while keeping most of the quality on it.

  46. 46. Why count tokens before sending a request?

    Correct answer: To stay within context limits and predict cost

    Libraries or the provider's token counting endpoint let apps trim history or documents before hitting limits.

  47. 47. How can an agent keep useful memory across long tasks?

    Correct answer: Save notes to storage and load relevant parts later

    External memory, such as files or a database, keeps the context small while preserving decisions and progress.

  48. 48. What should an AI feature's UI offer when answers can be wrong?

    Correct answer: Ways to see sources, edit, regenerate and report problems

    Good AI UX makes uncertainty visible and correction easy, which also produces feedback data for evals.

  49. 49. What is data poisoning?

    Correct answer: Planting malicious content in training or RAG data

    Poisoned documents in a RAG index can make the system give harmful or false answers. Control who can add content and monitor sources.

  50. 50. What is a supply chain risk for LLM apps?

    Correct answer: Compromised models, datasets, plugins or MCP servers

    Downloaded models, community tools and third-party MCP servers run with your app's privileges. Review and pin them like code dependencies.

  51. 51. Why should an MCP server you install be treated like any dependency?

    Correct answer: It can run actions and read data with your permissions

    A malicious or buggy server can leak data or perform unwanted actions. Check the source, permissions and updates.

  52. 52. What is unbounded consumption in LLM apps?

    Correct answer: Missing limits let users or attackers run up huge costs

    Per-user rate limits, max tokens, budget alerts and request size limits protect against bill shock and denial of service.

  53. 53. How do you test a feature that summarises long documents?

    Correct answer: Check key facts are kept, nothing is invented and length limits hold

    Combine code checks (length) with judged criteria (coverage, faithfulness) on a varied document set.

  54. 54. What should evals for an extraction feature (e.g. invoice to JSON) measure?

    Correct answer: Field-level accuracy against labelled examples

    Per-field precision and recall show which fields fail, such as dates or totals, guiding prompt or schema fixes.

  55. 55. What is the purpose of a refusal test set?

    Correct answer: Checking the model declines harmful requests but not harmless ones

    Two-sided tests catch both safety gaps and over-refusal, which frustrates users.

  56. 56. How should a team track prompt and model versions in production?

    Correct answer: Log the prompt version and model ID with each request

    When quality drops, you can tie it to a change. Versioned prompts can also be rolled back.

  57. 57. Why prefill or constrain the start of a model's answer in some cases?

    Correct answer: It steers format, e.g. starting with { for JSON

    Prefilling or structured output modes reduce chatty preambles like "Sure, here is the JSON" that break parsers.

  58. 58. What is the main advantage of putting examples in XML-like tags in a prompt?

    Correct answer: The model can tell examples from instructions

    Clear structure (<example>, <document>) reduces confusion in long prompts and makes them easier to maintain.

  59. 59. What can parallel tool calls improve in an agent?

    Correct answer: Latency, by running independent lookups at the same time

    Fetching weather in three cities can happen at once. Dependent steps still need to run in order.

  60. 60. What is the orchestrator-workers pattern?

    Correct answer: A lead model splits a task and delegates the parts

    Useful for tasks like changes across many files, where subtasks aren't known in advance.

  61. 61. Why are vector or embedding weaknesses listed as an LLM risk?

    Correct answer: Leaky or poisoned vector stores hurt answers and privacy

    Issues include missing access control, cross-tenant leaks and inversion attacks that recover text from embeddings.

  62. 62. How should an app handle a model answer that fails validation repeatedly?

    Correct answer: Stop after a few retries and use a fallback or clear error

    Bounded retries protect cost and latency. Log the failures; they're valuable eval cases.

  63. 63. What is misinformation in the OWASP LLM Top 10 sense?

    Correct answer: Users acting on false but convincing model output

    Overreliance turns hallucinations into real damage, such as wrong legal or medical advice. Grounding, disclaimers and human review help.

  64. 64. What is a guardrail model?

    Correct answer: A separate classifier that screens inputs or outputs

    Moderation and safety classifiers add a layer that doesn't depend on the main model following its instructions.

  65. 65. Why test an AI feature with inputs in several languages?

    Correct answer: Quality, safety and tokenization can differ between languages

    A guardrail tuned on English may miss harmful content in Ukrainian. Evals should reflect your users' languages.

  66. 66. What is the difference between code-graded and model-graded evals?

    Correct answer: Code checks exact rules; a model grades open qualities

    Use code where possible (JSON valid, contains ID); use a judge for tone, completeness or helpfulness.

  67. 67. What does "pass@k" mean for code-generating models?

    Correct answer: The chance that at least one of k samples passes the tests

    It measures capability when you can try several samples and check them, common in coding benchmarks.

  68. 68. Why keep humans in evaluation even with automated judges?

    Correct answer: Humans catch subtle problems and keep judges calibrated

    Regular human review of samples finds new failure types that become rubric items and test cases.

  69. 69. What should happen to user feedback like a thumbs down on an AI answer?

    Correct answer: Review it and turn real failures into eval cases

    Feedback is the best source of realistic test cases. Closing the loop improves quality over time.

  70. 70. What is a common mistake when building a first RAG prototype?

    Correct answer: Never measuring retrieval separately from answer quality

    When answers are bad, you need to know whether retrieval missed the passage or generation misused it.

  71. 71. What does streaming change for error handling?

    Correct answer: Errors can happen mid-answer, after part of the text is shown

    UIs need a state for interrupted answers, retries and partial output, and tests should simulate dropped streams.

  72. 72. Why should an AI feature have a cost budget per user or tenant?

    Correct answer: So a few heavy users or abuse can't run up huge bills

    Track spend per user, alert on spikes and degrade gracefully, for example to a smaller model, when limits are reached.

  73. 73. Why doesn't adding more retrieved chunks always improve RAG answers?

    Correct answer: Irrelevant chunks add noise and can push the model off track

    Precision matters as much as recall. A reranker and a sensible top-k keep the context focused and cheaper.

  74. 74. What should an agent do before an irreversible action like sending money?

    Correct answer: Ask a human to confirm, showing exactly what will happen

    Confirmation steps limit damage from mistakes and prompt injection. They should show the real parameters, not the model's summary of them.

  75. 75. Why run your own evals on a new model before switching to it?

    Correct answer: Benchmarks don't show how it does on your tasks and formats

    A model that's better on public leaderboards may break your JSON format or tone. Your eval suite is the real acceptance test.