LLM Evaluation and Observability Questions
Measuring and monitoring the quality of generative and LLM-powered systems. Covers evaluation approaches for open-ended outputs (human, model-graded, and reference-based), hallucination and safety checks, offline benchmarks versus online monitoring, and tracing and observability for production LLM applications. Emphasizes making non-deterministic systems measurable and trustworthy.
Problem (hard): Large generative models can memorize training examples and leak sensitive data. Propose metrics and a monitoring strategy to detect memorization and data leakage in production (including runtime checks, periodic audits, and red-team tests).
Sample Answer
Requirements & goals:
- Detect when a deployed generative model emits verbatim or near-verbatim training data (sensitive PII or secrets).
- Provide fast runtime protection and deeper periodic audits + adversarial (red-team) tests.
Metrics (quantitative): - Exact Match Rate (EMR): fraction of outputs that exactly equal any training-example.
- N-gram Overlap Score: % of outputs with n-gram (n≥6) overlap above threshold with training set.
- Exposure Score (Carlini et al.): estimated bits of information revealed per example using extraction attacks.
- KNN Memorization Score: fraction of outputs whose nearest training neighbor (in embedding space) is within distance d.
- Canary Detection Rate: whether injected synthetic canaries are reproduced (sensitivity gauge).
- Duplicate Generation Rate: percent of outputs that replicate any known sensitive token sequences.
- Perplexity Gap: difference in perplexity of generated text vs. training substring (low gap can indicate memorization).
Runtime protection & monitoring: - Online filtering: block or flag outputs with high EMR/N-gram overlap using an indexed hashed bloom filter of sensitive sequences (privacy-preserving, stored encrypted).
- Real-time scoring: compute lightweight KNN via approximate nearest neighbor (Faiss/HNSW) on hashed embeddings; if score > threshold, quarantine response and escalate.
- Canary probes: periodically query model with seeded prompts to check for canary leakage; track Canary Detection Rate.
- Rate-limited logging: store only risk-metadata (scores, hashes, no raw user text) to comply with privacy; use secure audit logs.
Periodic audits: - Full extraction attack runs monthly: run beam-search, temperature sweeps, and model inversion techniques to attempt recoveries; measure Exposure Score and EMR.
- Large-scale n-gram scan: compare generated corpus against training corpus via shingling and locality-sensitive hashing to find near-matches.
- Differential testing across checkpoints/hyperparams to see memorization trends.
Red-team tests (adversarial): - Human + automated red team crafts prompts designed to elicit memorized sequences: partial prompts, roleplay, prompt chaining, prompt injection.
- Use adaptive attacks: soft-prompt, prefix-tuning, and gradient-based extraction where applicable.
- Threat modeling: simulate insider training-data leaks to prioritize sensitive classes and update canaries.
Alerting, thresholds & response: - Define tiered alerts: high-risk (canary reproduced, EMR>0.1% with sensitive class) triggers immediate rollback/serving block; medium-risk opens incident for investigation.
- Triage: automated suppression, notify privacy/security, start forensics (which training shard, which checkpoint).
Operational considerations: - Privacy-preserving storage: store training fingerprints (hashes, embeddings) encrypted; access restricted.
- Explainability: log provenance (model version, prompt, user id, risk-scores) for audits.
- Continuous improvement: retrain with dedup/DP techniques, employ Differential Privacy (DP-SGD) and detection-informed scrubbing of training data.
Key trade-offs: - False positives vs. latency: heavier runtime checks increase latency; use approximate methods online and full checks offline.
- Coverage vs. storage/privacy: keep fingerprints compact (LSH, bloom filters) to avoid storing raw sensitive data.
This combined strategy gives layered defense: fast runtime blocking, scheduled deep audits, and adversarial probing to surface memorization risks and drive remediation.
Define perplexity for language models and explain what higher and lower perplexity indicate. For next-token prediction tasks, how would you evaluate model quality using perplexity together with token overlap metrics such as BLEU or ROUGE?
Sample Answer
Perplexity is an information-theoretic measure of how well a probabilistic language model predicts a sequence. Formally, for a test set of tokens w1..wN, perplexity = exp(−(1/N) * sum_{i=1..N} log p(wi | context)). It equals 2^{cross-entropy} and lower perplexity means the model assigns higher probability to the observed tokens (better predictive fit); higher perplexity means poorer predictions or more uncertainty.
Interpretation:
- Lower perplexity → model is more confident and accurate at next-token prediction on that distribution.
- Higher perplexity → model is less certain or miscalibrated; may indicate mismatch between train and test data.
Using perplexity with token-overlap metrics (BLEU/ROUGE) for next-token prediction:
- Complementary signals: perplexity measures probabilistic fit across all possible tokens; BLEU/ROUGE measure overlap between generated sequences and reference(s), so they capture surface similarity and fluency for specific outputs.
- Evaluation recipe:
- Ensure identical tokenization and vocabulary when computing both metrics.
- Report corpus-level perplexity alongside BLEU/ROUGE on generated sequences (e.g., greedy/beam/hypotheses).
- Use perplexity to compare model likelihoods (good for model selection, calibration, detecting data shift). Use BLEU/ROUGE to judge generation quality for a given decoding strategy.
- Be cautious: low perplexity doesn’t guarantee high BLEU/ROUGE (model might be overconfident but produce generic tokens); conversely, high BLEU with high perplexity could come from copying heuristics.
- For fair comparison, control decoding (temperature, beam size) and report human eval if possible.
Practical tips: report token-level cross-entropy, use length normalization for BLEU/ROUGE comparisons, and evaluate on in-distribution and out-of-distribution sets to separate calibration from surface quality.
You are evaluating a large language model (LLM) for use in customer support. Propose a risk assessment checklist covering hallucination, privacy leakage, latency, cost, and alignment to brand tone. For each risk, suggest one technical control or guardrail.
Sample Answer
Situation: We're evaluating an LLM for customer support—goal is safe, reliable, on‑brand automated responses. Below is a concise risk-assessment checklist (risk → measurable criteria → one technical control/guardrail), tailored for an MLE deploying production systems.
- Hallucination
- Criteria: % of responses with verifiable factual errors > 1% on sampled queries; user-reported false info rate.
- Guardrail: Retrieval-augmented generation (RAG) with citation forcing — require model to condition on verified KB passages and include provenance; if retrieval confidence below threshold, trigger safe fallback (template answer + human escalation).
- Privacy leakage
- Criteria: Detection of PII in outputs; successful extraction rate in red-team prompts = 0.
- Guardrail: PII filter and differential privacy at training/inference: block/obfuscate detected PII in prompts/outputs and enforce prompt sanitization + DP/noise for logs.
- Latency
- Criteria: 95th percentile latency < 300ms (or business SLA).
- Guardrail: Multi-tier serving: distilled local model for low-latency simple intents, async heavy model for complex queries; circuit-breaker to route when overloaded.
- Cost
- Criteria: Cost per session ≤ budget; monthly spend variance <10%.
- Guardrail: Hybrid routing + budgeting: intent classifier to send only complex sessions to expensive LLM; usage caps and dynamic throttling.
- Alignment to brand tone
- Criteria: Automated scoring against style rubric (politeness, brevity, friendliness) — pass rate > 95%.
- Guardrail: Constrained decoding + style-conditioned finetune and a lightweight classifier that vetoes out-of-tone responses and requests rewrites or human review.
Monitoring & Ops: continuous red-teaming, automated telemetry (error/ESCALATE rates), regular audits, and human-in-the-loop review for edge cases.
Microsoft is integrating large language models across products. As a principal ML Engineer, outline technical, policy, and monitoring frameworks to manage hallucination, prompt injection, unsafe outputs, and model updates at scale. Describe automated detection and human-in-the-loop workflows.
Sample Answer
Requirements & goals (clarify): minimize hallucination and unsafe outputs across products while allowing timely model updates; detect and mitigate prompt-injection; provide scalable automated defenses plus human oversight for high-risk cases; measure and preserve user experience and latency SLOs.
Technical framework
- Input hardening: canonicalize inputs, normalize encodings, strip/flag embedded instructions, sandbox file/URL parsing; per-product allowed-action policy.
- Defense-in-depth: combine prompt sanitization, context-aware instruction-filter, and runtime policy engine that enforces allowed API calls, data exfiltration checks, and rate-limits.
- Grounding & retrieval augmentation: use RAG with retrieval confidence scores, provenance metadata, and a retrieval-checker model that rejects low-overlap or unsupported claims.
- Factuality/verifier model: lightweight, specialized verifier (or ensemble) that computes factuality/confidence, cross-checks against trusted knowledge graphs and sources, returns structured evidence or “I don’t know.”
- Adversarial prompt detection: binary/soft classifier trained on prompt-injection corpora + behavioral signals (e.g., sudden system instruction tokens, unusual token statistics).
- Explainability hooks: token-level logits, attention summaries, and provenance links emitted for downstream policy decisions.
Policy & governance
- Product risk tiers: define low/medium/high depending on actions (e.g., code execution, legal/medical advice). Each tier mandates different checks and HITL thresholds.
- Acceptable use & escalation: mapped to product tiers; automated blocking for explicit violations; human review for ambiguous/critical refusals.
- Model update policy: controlled CI/CD with unit tests, red-team tests, safety regression suites, privacy checks, security scans, and cross-functional sign-off before rollout.
- Access controls & auditing: role-based access, immutable audit logs for requests/responses/decisions, versioned policy artifacts.
Monitoring & metrics
- Core metrics: hallucination rate (verified false claim fraction), safe-fail rate (false positives blocking benign outputs), toxicity score, prompt-injection detection rate, verifier confidence, downstream error rate.
- Observability: real-time dashboards, latency/SLOs, per-version/per-segment metrics, broken-down by risk tier and client.
- Drift & distribution checks: monitor input distribution, retrieval changes, model output distribution, and increase sampling for human review when drift detected.
Automated detection pipeline
- Multi-signal detectors:
- Pattern/heuristic layer (regex, token-sequence rules) for known injections.
- ML classifier for adversarial prompts (ensemble of shallow and deep models).
- Runtime verifier that checks factual claims against knowledge sources; computes provenance score.
- Consistency checker: re-roll multiple seeds or temperature and compare inconsistency score.
- Decisioning: detectors emit risk score and reason codes; policy engine maps score+product tier to actions: allow, sanitize, ask clarification, call verifier, or block+escalate.
Human-in-the-loop workflows
- Tiered triage:
- Automatic safe responses for low-risk.
- Confidence-thresholded escalation: if verifier/confidence under threshold or risk score high, send to human review queue.
- Rapid-review UI: shows user query, model output, provenance, classifier reasons, and recommended action templates. Humans can accept, edit, annotate (for retraining), or escalate to specialists.
- Feedback loop: human labels feed retraining pipelines (adversarial examples, false positives/negatives). Use active learning to prioritize uncertain/high-impact cases.
- SLAs & staffing: map risk tiers to SLA (e.g., seconds for interactive clarifications, hours for legal/medical escalations).
Model updates & lifecycle
- Safety CI: automated red-team suite, targeted adversarial tests, metric gating (no increase beyond X% in hallucination/toxicity), canary rollout (shadow traffic + A/B), progressive rollout with rollback triggers.
- Continuous learning: offline retraining using curated human-reviewed data; separate pipelines for safety head vs. base model; human-in-the-loop augmentation for rare failure modes.
- Versioning & rollback: immutable model artifacts, dataset snapshots, and policy configurations; automated rollback when safety SLOs violated.
Operational considerations & trade-offs
- Latency vs. safety: heavier verification for high-risk paths, lightweight heuristics for low-risk; fallbacks to terse refusals to preserve latency.
- False positives vs. user trust: tune thresholds per product; provide transparent failure messages and escalation options.
- Scalability: microservice architecture for detectors/verifiers; caching of provenance and retrieval results; sampling-based human review to limit cost.
Example end-to-end flow (user asks legal question)
- Input hardening + prompt-injection classifier → low injection score.
- RAG retrieval returns sources; verifier computes low provenance/confidence on a claim.
- Policy engine (legal = high-risk) routes to human queue; model returns a provisional response: “I’m not confident — here’s what I found,” with sources.
- Human reviewer checks sources, edits output, labels case.
- Label enters retraining/active learning pipeline; metrics update; if systemic, triggers model update and gated rollout.
This combined stack—prevention, detection, verification, HITL, rigorous CI/CD and monitoring—balances safety, user experience, and scalability for enterprise-grade LLM integration.
For a text summarization system, compare ROUGE, BLEU, and simple token overlap metrics. Explain strengths and weaknesses of each and propose a hybrid offline evaluation strategy that combines automated metrics and human evaluation to estimate summarization quality for product launch decisions.
Sample Answer
ROUGE, BLEU and simple token-overlap measure different aspects of summarization; each has strengths and limits.
- ROUGE (recall-focused n‑gram overlap, ROUGE-L): Strengths — correlates reasonably with content coverage, widely used, easy to compute. Weaknesses — favors longer outputs, insensitive to paraphrase or synonymy, poor at evaluating faithfulness/fluency.
- BLEU (precision-oriented, n‑gram overlap): Strengths — penalizes verbosity, useful for measuring concise matching (common in MT). Weaknesses — designed for translation, low correlation with human judgment on single-reference summaries, brittle to paraphrase and word order differences.
- Simple token overlap / Jaccard: Strengths — trivial to compute, interpretable for exact matches. Weaknesses — ignores syntax, ordering, semantics; inflated by stopwords; poor for paraphrase or abstractive summaries.
Given these limitations, propose a hybrid offline evaluation for product-launch decisions:
-
Automated tier (scale/filter):
- Compute ROUGE (1/2/L) and BLEU plus semantic metrics: BERTScore and MoverScore to capture paraphrase/semantic similarity.
- Compute factuality checks (QA-based entailment, FactCC or a black-box QA-consistency test) and simple novelty/length penalties.
- Define pass/fail thresholds (e.g., ROUGE-L > X AND BERTScore > Y AND factuality recall > Z) to filter obvious failures.
-
Stratified human evaluation (final quality assurance):
- Sample outputs stratified by automated-score bands (high/mid/low) and content type.
- Use expert annotators for key dimensions: faithfulness (factual consistency), relevance/coverage, coherence/structure, and fluency. Use 5‑point Likert scales and binary critical-failure flags.
- Compute inter-annotator agreement (Krippendorff’s alpha) and adjudicate disagreements.
- Collect qualitative failure examples and time-to-interpret metrics (how long raters need).
-
Decision rules & metrics for launch:
- Convert human scores to composite quality index (weighted: faithfulness 40%, relevance 30%, coherence 20%, fluency 10%).
- Require both automated pass rate (e.g., ≥90% of sampled outputs pass automated filters) and composite human index above threshold. Inspect any critical-failure rates (<2%).
- Run A/B small-scale user trials if feasible to measure downstream KPIs (task success, satisfaction).
-
Operational considerations:
- Calibrate automated thresholds using initial human-labeled pilot.
- Use a small continuous human-in-the-loop monitoring post-launch for drift/factuality.
- Balance cost by routing only borderline/high-impact samples to experts; use crowd-workers for low-risk bulk labeling.
This hybrid combines scalable automated screening with targeted, expert human judgment focused on faithfulness and user impact—appropriate for responsible product launch decisions.
Unlock Full Question Bank
Get access to all 7 LLM Evaluation and Observability interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.