← Questions

How would you prevent hallucinations in an LLM-based system?

0
SpaceXAIAI/ML designLast asked Nov 2025

An AI/ML design interview question asked in SpaceXAI's short screen with an engineer, last asked Nov 2025. It tests llm, hallucinations and evaluation.

How would you prevent, or at least sharply reduce, hallucinations in an LLM-based product? Explain why models hallucinate, then the concrete techniques you would apply across the stack: training, inference, retrieval and grounding, verification, product design and evaluation, so the system stops stating false or unsupported things with confidence.

Requirements

  • Define hallucination for the product: unsupported claims, factually false claims, fabricated citations or tool results.
  • Mitigations organized by where they act: before generation (data, fine-tuning), during generation (grounding, prompting, decoding), after generation (verification, UX).
  • How you measure hallucination and track it over model and prompt changes.
  • Assume a production application where you can fine-tune, prompt and build around the model, and where latency and cost matter. Be honest that hallucination can be reduced and contained, not eliminated.

Clarifying questions

  • What product: open-domain chat, Q&A over private documents, code generation, or an agent that acts?
  • How costly is a wrong answer here?
  • Do we control the model, or only call a third-party API?
  • Is there an authoritative source to ground against?
  • What latency and cost budget per request?

What a strong answer covers

  • Causes: next-token training rewards fluent guesses; gaps or stale knowledge; prompts that pressure the model to answer; long contexts where evidence is missed.
  • Grounding as the biggest lever: retrieval or tool calls that put authoritative context in the prompt, with instructions (and fine-tuning) to answer only from it, cite it, and abstain otherwise.
  • Verification: checking each claim against the retrieved sources (an entailment model or an LLM judge), self-consistency for high-stakes answers, and structured outputs validated against schemas or databases.
  • Training: fine-tuning on examples that reward "I don't know" when evidence is missing, and preference data that penalizes unsupported claims, without making the model evasive.
  • Product: show sources, show confidence, let users report errors, route uncertain cases to a human.
  • Evaluation: a labelled set of questions with known answers and unanswerable ones, faithfulness metrics on every change, and production sampling.

Follow-ups

  • Your RAG system still contradicts its own retrieved passages. Why, and how do you fix each cause?
  • Build an automated pipeline that measures hallucination rate on every change. What is the ground truth?
  • When should the model say "I don't know", and how do you train that without it becoming useless?
  • What changes for an agent that calls APIs and writes code?

Where it's asked

What it tests

llm · hallucinations · evaluation

Your canvas
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing