📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

Why does an LLM sometimes give confident but wrong answers (hallucination), and what can a .NET developer do to reduce it?

Beginner Theory Beginner ai evaluation hallucination microsoft-extensions-ai rag structured-output

🎯 Key points

  • Generation is next-token prediction, optimised for plausibility not truth
  • Low temperature reduces randomness, not missing knowledge
  • Ground with retrieved sources and allow 'I don't know'
  • Require citations as chunk ids and verify them in code against what was retrieved
  • GetResponseAsync<T>() structured output plus FluentValidation
  • Trace with UseOpenTelemetry() to inspect prompts and answers
  • Score groundedness with Microsoft.Extensions.AI.Evaluation in CI
  • Grounding and checks cost tokens and latency; size them to the risk

⏱ 30-second answer

An LLM predicts likely tokens, not true ones. When its training data lacks the fact or the prompt is ambiguous, it still produces fluent text, and lowering temperature reduces randomness but not ignorance. In .NET I reduce it in layers:

  • Ground the model with RAG (retrieved chunks in the prompt) and tell it to answer only from them and say "I don't know" otherwise.
  • Ask for citations as chunk ids and check in code that each id was actually retrieved.
  • Use structured output (IChatClient.GetResponseAsync<T>() in Microsoft.Extensions.AI) and validate the object with FluentValidation or data annotations.
  • Measure: trace calls with UseOpenTelemetry() and score groundedness with GroundednessEvaluator from Microsoft.Extensions.AI.Evaluation in CI.

The trade-off is that grounding and checking add tokens and latency, so you size them to the cost of a wrong answer.

🔍 What the interviewer is checking

Checks understanding that generation is probabilistic, not fact lookup, and that the developer controls the guardrails in code.

Green flags

  • Explains next-token prediction in one sentence
  • Separates temperature from knowledge
  • Names grounding, citation checks, validation and evaluation

Red flags

  • "Set temperature to 0 and it stops hallucinating"
  • Trusts the model's output without any check in code

↩ Usually asked after

More in .NET and AI

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me