Artificial Intelligence (GenAI) Interview Questions

Use the filter to quickly find topics like transformers & attention, RAG/vector search, fine-tuning & LoRA, evaluation & guardrails, prompt engineering, agents/tool use, and deployment/monitoring.

Showing 100 of 100
  1. What is the difference between traditional ML, classical NLP, and Generative AI based on foundation models?
    Traditional ML learns task-specific mappings (e.g., classifiers) from labeled data. Classical NLP relied heavily on rules and small statistical models with hand-engineered features. Generative AI uses large foundation models (Transformers) pretrained on massive corpora with self-supervision and then adapted via prompting, RAG, or fine-tuning to perform many downstream tasks with little or no labeled data.
  2. Briefly explain how the Transformer architecture generates text.
    Input text is tokenized and embedded; self-attention layers compute contextualized representations by weighting other tokens. Positional encodings inject order information. A stack of decoder (or encoder-decoder) blocks produces next-token logits which are converted to probabilities and sampled/decoded to generate text autoregressively.
  3. Why do tokenization and context window size matter for LLM applications?
    Tokenization (BPE/SentencePiece) determines how text is split and therefore affects prompt length, cost, and OOD behavior on unusual tokens. The context window caps how much the model can attend to at once; long prompts increase latency/cost and can dilute attention. Good chunking, summarization, and retrieval are used to stay within limits while preserving relevant signal.
  4. Compare decoding strategies: greedy, beam search, top-k, top-p, and temperature.
    Greedy chooses the highest-prob token each step (fast, deterministic, but bland). Beam search explores multiple high-prob paths (good for structured tasks but can be slow and repetitive). Top-k and top-p (nucleus) sampling sample from a truncated distribution to balance creativity and coherence; temperature scales logits to control randomness—lower is more deterministic.
  5. What is hallucination in LLMs and how do you mitigate it?
    Hallucination is confident but unsupported or false output. Mitigations include Retrieval-Augmented Generation (RAG) with citations, constrained decoding (JSON/regex/grammar), fact checking or reranking, tool use (e.g., calculators, search), system prompts that demand sources, and task-specific evals (faithfulness, groundedness) with guardrails or human review for high-risk flows.
  6. Describe a robust RAG architecture for production.
    Pipeline: (1) ingest and chunk content with metadata; (2) embed chunks; (3) store in a vector DB with ANN index (e.g., HNSW/IVF-PQ); (4) at query time, rewrite/expand the query, retrieve top-k, optionally rerank cross-encoder; (5) build a grounded prompt with citations; (6) generate; (7) log and evaluate. Add freshness policies, per-tenant isolation, and caching.
  7. How do you choose chunking and embeddings for RAG?
    Use semantic chunking (by headings/sentences) with overlap (e.g., 150–400 tokens, 10–20% overlap) to preserve context. Pick domain-appropriate embeddings (general vs. code vs. multilingual), normalize vectors, and store rich metadata for filtering. Validate with retrieval recall/precision and ablate chunk sizes, overlaps, and query rewriting.
  8. What are HNSW, IVF-Flat, and Product Quantization (PQ) in vector search?
    They are ANN index types. HNSW is a graph-based index with excellent recall/latency for many workloads. IVF partitions vectors into coarse clusters (inverted lists) for faster lookup; IVF-PQ compresses vectors for memory savings at some recall cost. Choice depends on scale, memory/latency budget, update rate, and recall requirements.
  9. When would you use prompt engineering vs. fine-tuning vs. adapter-based tuning (LoRA/QLoRA)?
    Start with prompting/RAG for flexibility and lowest risk. Use instruction or adapter tuning when you need domain-specific style, compliance, or to reduce prompt length/latency. Full fine-tuning is used when adapters are insufficient, you control weights on-prem, or you need deep capability shifts—acknowledging higher cost, data needs, and governance burden.
  10. Explain LoRA and QLoRA.
    LoRA injects small low-rank matrices into weight updates so only adapter parameters are trained—memory efficient and easily swappable. QLoRA adds quantization (e.g., 4-bit NF4) of base weights to further reduce memory while training adapters, enabling fine-tuning of larger models on a single or few GPUs with minimal quality loss.
  11. How do you enforce structured outputs from an LLM?
    Use explicit schemas and instructions, JSON mode or function/tool calling with argument validation, and constrained decoding via grammars or regex. Add robust parsing with retries and self-correction, and log schema violations. For critical flows, couple the LLM with deterministic validators and business rules.
  12. What are function calling/tools and why are they important?
    Function calling lets an LLM produce structured tool invocations (e.g., search, DB query, calculator). This grounds outputs in external systems, reduces hallucinations, and enables complex workflows. Production designs include tool schemas, idempotency, timeouts, sandboxing, and explicit authorization to prevent overreach.
  13. How do you evaluate a GenAI system beyond perplexity?
    Use task-specific metrics: for RAG—answer relevance and faithfulness/groundedness; for summarization—consistency and coverage; for generation—human or model-assisted pairwise ratings. Build an eval harness with golden sets, negative cases, and regression tests; monitor online quality with A/B tests and human-in-the-loop review for sensitive tasks.
  14. What techniques reduce latency and cost in production LLM apps?
    Batching, KV-cache reuse, response streaming, prompt compression, retrieval gating, and caching of common prompts help. Use smaller/faster models for routing or first pass, speculative decoding, quantized/compiled runtimes, and right-size context. Profile token-in/out, time-to-first-token, and throughput under load.
  15. How do you implement observability and quality monitoring for LLM apps?
    Log prompts, generations, latencies, token counts, tool calls, and costs with trace IDs and PII controls. Capture user feedback, evaluation scores, and safety events. Build dashboards and alerts for drift, spike, or failure patterns; enable replay for incident analysis and prompt/version diffing.
  16. Discuss safety and compliance considerations for GenAI in production.
    Apply input and output filtering (toxicity, PII, jailbreak detection), redaction, and policy prompts. Enforce data residency, retention, and tenant isolation; restrict training on user data by default. Perform red-teaming and maintain audit trails; add human review for high-risk domains (finance, health, legal).
  17. What is prompt injection, especially in RAG, and how do you defend against it?
    Prompt injection occurs when retrieved content or user input contains instructions that override the system prompt. Defenses: treat retrieved text as untrusted data, use explicit system policies, delimit sources, apply content sanitization, disallow tool execution from untrusted instructions, and use allow-listed functions with confirmation steps.
  18. Explain quantization and knowledge distillation for LLMs.
    Quantization reduces precision (e.g., FP16→INT8/INT4) to shrink memory and improve speed with acceptable quality loss; use quant-aware training or better quantizers (NF4/GPTQ/AWQ) for minimal degradation. Distillation trains a smaller student to imitate a larger teacher, often combined with adapters and task-specific data to preserve performance at lower cost.
  19. How do you manage conversational memory safely and effectively?
    Separate short-term context (recent turns) from long-term memory (summaries or vector store). Summarize and filter for relevance, apply PII redaction, and scope memory per user/tenant with retention limits. Rehydrate only necessary facts into prompts to control cost and leakage.
  20. What are common prompt design patterns for reasoning?
    Use ReAct (reason + act) for tool-augmented tasks, chain-of-thought or step-by-step for transparency (mindful of safety and leakage), and self-consistency or multi-prompt voting to improve reliability. For planning, apply Tree-of-Thought/graph-of-thought variants with cost caps and guardrails.
  21. When would you host models on-prem/self-managed vs. call a managed API?
    Self-hosting provides data control, customizability, and potentially lower unit costs at scale but requires MLOps/GPU expertise and capacity planning. Managed APIs offer rapid iteration, best-in-class models, and elastic scaling with vendor lock-in and data governance agreements. Many enterprises use a hybrid router to pick per-request.
  22. How do temperature, repetition penalty, and presence/frequency penalties affect outputs?
    Temperature controls randomness globally by scaling logits. Repetition penalty and presence/frequency penalties discourage the model from reusing tokens or encourage novelty, which reduces loops and improves variety. Tune per task and keep deterministic settings for evaluable or compliance-sensitive flows.
  23. What is a reranker and where does it fit in RAG?
    A reranker (often a cross-encoder) re-scores retrieved passages against the query or draft answer to improve relevance and faithfulness. Place it after vector retrieval and before prompting (or post-generation for citations). It can boost quality significantly with a modest latency trade-off.
  24. Describe a resilient production architecture for LLM apps.
    Include a gateway/orchestrator with prompt templates and versioning, a model router with fallbacks and canaries, RAG and tool subsystems, guardrails, observability, and caching. Use circuit breakers, retries with idempotency, and rate limits. Keep prompt/data configs outside code to allow fast, audited iteration.
  25. How do you build and maintain high-quality datasets for tuning and evaluation?
    Curate diverse, de-duplicated, and permissioned data with clear licenses. Create task-specific instruction data, edge cases, and counter-examples; use data programmatically generated then human-vetted. Maintain versioned datasets and an eval set separate from training to avoid overfitting; continuously add real-world failure cases.
  26. Compare RLHF with newer preference-optimization methods like DPO/ORPO.
    RLHF uses a reward model + PPO to adjust the base model toward preferred outputs, but it’s complex and can be unstable. Direct Preference Optimization (DPO) and variants (e.g., ORPO) skip the reward model and optimize directly on chosen vs. rejected pairs with a contrastive objective, simplifying training, improving stability, and often matching RLHF quality with less engineering.
  27. What multi-agent patterns are useful in GenAI systems?
    Common patterns include Planner–Solver (a planning agent decomposes tasks for tool-using solvers), Debate/Self-Consistency (agents critique and vote), and Specialist Ensembles (router dispatches to experts like code, math, or search). Guard with budgets, timeouts, and a coordinator that enforces termination and validates intermediary outputs.
  28. How do you implement guardrails for safety and policy compliance?
    Layer defenses: input filters (PII/toxicity/jailbreak), system prompts with explicit policies, constrained decoding (grammar/regex/JSON), tool allow-lists, and output classifiers for safety and groundedness. Keep an audit trail and use policy simulators/red-team suites; fail closed for high-risk actions.
  29. Explain prompt caching and KV-cache reuse in inference.
    Prompt caching stores full request→response to avoid recomputation. KV-cache reuse stores attention key/values for the prompt so only new tokens are computed on continuation, dramatically reducing latency and cost for repeated system/shot prompts or chat history. Pair with template versioning and cache invalidation rules.
  30. What are effective strategies for long-context tasks?
    Prefer retrieval (RAG) with chunking + rerankers; summarize and stitch. If you must go long, use models with sliding-window or RoPE-scaled attention and apply context packing, attention sinks, or segment-wise generation. Monitor quality: long contexts can dilute relevance and increase latency/cost.
  31. How do you handle data governance and tenant isolation in GenAI apps?
    Isolate data per tenant in both object and vector stores, encrypt at rest/in transit, and tag embeddings with tenant metadata for filter-by-policy retrieval. Redact PII pre-ingest, limit retention, and block training on user content unless explicitly consented; maintain access logs and DPIA/records of processing.
  32. How should you evaluate LLM answers without relying only on judge LLMs?
    Use mixed methods: curated golden sets, exact/fuzzy metrics for structured tasks, human double-blind ratings, and model-assisted rubric scoring for scale. Beware position/verbosity bias in judge LLMs; add randomized A/B prompts and calibration to reduce bias; validate with human adjudication samples.
  33. Describe model routing at the service layer.
    A router selects the cheapest model that meets task constraints based on intent, safety, and difficulty (e.g., small policy model → fast model; fallback to stronger model on uncertainty). Implement with heuristics or classifiers, log decisions, and add canary/rollback paths for reliability.
  34. How do you manage embedding drift over time?
    Pin an embedding model version and re-embed on version changes. Track retrieval recall over time; if content or queries shift, run shadow indexes and A/B the new embeddings. Maintain dual indexes during migration and backfill asynchronously with change-data capture.
  35. What is hybrid retrieval and when is it useful?
    Hybrid retrieval combines sparse (BM25/splade) and dense vectors to capture lexical exact matches and semantic similarity. Often improves recall on rare terms, numbers, and entities. Use weighted fusion and then rerank with a cross-encoder before prompting.
  36. How do you keep a RAG system fresh as documents change?
    Use an ingestion pipeline with CDC/webhooks, document fingerprinting, and incremental chunk reprocessing. Version chunks, invalidate affected embeddings, and maintain time-aware filters; for news-like data, add a recency boost and freshness SLA dashboards.
  37. Open-source vs. managed LLMs: what factors drive the decision?
    Managed APIs offer top quality and elasticity with strong SLAs; trade-offs include cost predictability and data-sharing agreements. Open-source/self-hosted improves control, on-prem data guarantees, and customization; requires GPU ops, security hardening, and license compliance (e.g., LLaMA’s license vs. Apache).
  38. How do you make tool/function calling reliable?
    Define strict JSON schemas and validate; add idempotent endpoints, timeouts, and retries with backoff. Include tool selection hints in prompts, and log tool errors for auto-retry with clarified arguments. For destructive actions, require user confirmation or a secondary approval model.
  39. What orchestration and tracing approaches do you recommend?
    Use a thin orchestrator (custom or frameworks) with typed prompts, templating, and versioning. Trace every step (retrieval, tools, generations) with IDs, token/latency/cost metrics, and payload snapshots (PII-safe). Enable replay and diffing to investigate regressions.
  40. Discuss high-throughput inference serving for LLMs.
    Use engines like vLLM (paged attention, efficient KV-cache) or TensorRT-LLM for GPU-optimized kernels; enable batching and continuous batching. Profile TTFB and tokens/sec, pin max concurrency per GPU, and prefer streaming responses. Place a rate-limiting gateway in front.
  41. What are practical tips for LoRA/QLoRA fine-tuning?
    Target attention and MLP projection matrices; start with rank 8–16 and tune alpha/dropout. Use 4-bit base weights (NF4) for memory efficiency, mix precision for stability, and early-stop on validation. Keep adapters per task/tenant and hot-swap at runtime.
  42. How do multimodal LLMs work, and where do they shine?
    They fuse visual/audio encoders with language decoders via projection layers, enabling VQA, chart/OCR understanding, and UI agents. They excel when text needs grounding in images or screenshots; add OCR/textboxes to improve retrieval and cite regions in answers.
  43. Best practices for secure code generation with LLMs?
    Use test-first prompts and request unit tests; sandbox execution, limit network/FS access, and scan outputs with SAST/linters. Enforce dependency allow-lists and license checks; never run generated code in production without review.
  44. What is content provenance (e.g., C2PA) and watermarking in GenAI?
    Provenance standards like C2PA attach tamper-evident metadata proving origin and edits. Watermarking tries to embed detectable signals in generated media/text. Use provenance where supported; treat watermarks as helpful but not foolproof—they can be removed or degrade.
  45. How do you address bias/NSFW risks in image or text generation?
    Apply pre- and post-filters (vision/text safety models), prompt normalization, and blocked concept lists. Provide user controls (e.g., neutral styles), perform fairness audits on representative sets, and add human review for sensitive categories.
  46. How can synthetic data help fine-tuning, and what are the pitfalls?
    Synthetic instruction data (self-instruct, augmentation) can bootstrap domain expertise and style. Pitfalls: compounding model biases, leakage of incorrect facts, and overfitting to generator quirks. Mitigate with human vetting, deduplication, and diverse sources.
  47. How do you model and control GenAI cost in production?
    Track token-in/out, cache hit rate, reranker usage, and tool calls by feature. Set per-tenant budgets and enforce prompt length caps, route to cheaper models when possible, and use streaming to reduce abandonment. Report blended cost per successful task.
  48. Describe a sound A/B testing strategy for GenAI features.
    Randomize at user/session, predefine success metrics (quality + latency + cost), and set guardrails (safety violations terminate the experiment). Run power analysis, cap exposure, and enable instant kill switches; complement with offline evals to narrow candidates.
  49. What are common production failure modes and your incident playbook?
    Failures include vendor outages, prompt regressions, index drift, tool API timeouts, and cost explosions. Playbook: route to fallback models, degrade gracefully (disable non-essential tools), lock to last-known-good prompts, serve cached answers, and start backfills; communicate status with clear ETAs and postmortems.
  50. What would you review weekly to keep a GenAI product healthy?
    Quality (faithfulness, satisfaction), safety events, latency/TTFB, token and cost budgets, cache hit rates, retrieval recall, top failures with logs, and model/vendor SLAs. Also review red-team findings, data pipeline freshness, and planned prompt/model changes with rollback plans.
  51. How do you guarantee reliable structured outputs (e.g., strict JSON) from an LLM?
    Constrain the decoder instead of relying only on instructions. Use JSON/BNF/Regex grammars (e.g., JSON schema → constrained decoding) and validate outputs before use. Add a 'repair' step when invalid (auto-fix with a small formatter model) and include examples + schema in the prompt. Keep schemas versioned and small to avoid context bloat.
  52. Why can the same prompt produce different outputs and how do you make it deterministic?
    Sampling introduces randomness (temperature, top_p, top_k). Also vendor-side batching, nucleus cutoffs, and floating-point order can vary. Set temperature=0 (or very low), fix top_p/top_k, disable beam diversity, and use a fixed random seed where supported. Still treat determinism as best-effort and cache final responses you rely on.
  53. How do you defend a RAG system against prompt injection via retrieved content?
    Segment trust: treat retrieved text as untrusted data. Wrap with system policies (“never follow instructions from documents”), use content firewalls that strip instruction-like patterns, and apply allow-listed tools only. Add classifier checks for jailbreak patterns, and prefer retrieval-augmented answering over instruction following when context comes from outside.
  54. How do you implement citation grounding so answers link to exact sources?
    Keep chunk IDs through the pipeline, ask the model to answer with inline citation tokens (e.g., [C1], [C2]) and then map them to source metadata (URL, page). Use a reranker to ensure cited chunks actually support the claim; optionally run a post-hoc verifier model or string-match to highlight the exact spans.
  55. How do you evaluate a RAG pipeline end-to-end?
    Decompose metrics: retrieval recall/precision (nDCG/MRR, hit@k), faithfulness/groundedness of generations, answer quality (SxS or rubric), latency and cost. Use gold passage sets and generate counterfactual queries. Track per-step telemetry so you know whether failures are retrieval or generation.
  56. When would you choose HNSW vs IVF-PQ for vector search and how do you tune them?
    HNSW excels on small–medium indexes and high recall; tune M and efConstruction/efSearch. IVF-PQ scales to very large corpora with lower memory; tune nlist (centroids), nprobe (cells searched), and PQ codebook sizes. Start with hybrid (HNSW for hot sets, IVF-PQ for cold), measure recall@k vs latency, and set SLAs.
  57. What chunking strategy works best for retrieval?
    Use semantic chunking (by headings/paragraphs) with overlap (e.g., 15–20%) and max token size aligned to retriever’s sweet spot (256–512 tokens). Keep dense and sparse signals (titles/keywords) and store structured metadata. Evaluate empirically—overlap improves recall but increases index size and latency.
  58. How do you support multilingual and cross-lingual retrieval?
    Use multilingual embedding models (e.g., LaBSE/MUSE) or translate-query/translate-doc pipelines. Normalize punctuation/case, and store language codes for filtering. Cross-lingual reranking with a multilingual cross-encoder improves precision. Watch for script/segmentation quirks and evaluate per-language.
  59. What are best practices for streaming responses to the UI?
    Use server-sent events or WebSockets; render tokens incrementally with a typewriter effect, show a stop button, and surface partial citations progressively. Handle backpressure and allow mid-stream tool calls. Log tokens/sec and TTFB; fall back to non-streaming on flaky networks.
  60. How do you manage session memory without runaway context growth?
    Summarize and distill conversation state into a compact scratchpad, store facts in a short-term memory vector store, and expire or archive older turns. Use role-aware memory (user profile vs task state), size caps, and automatic pruning policies. Keep the system prompt small and versioned.
  61. How should secrets and PII be handled in prompts and logs?
    Never place secrets directly in prompts; use vaults and short-lived tokens. Redact PII pre-prompt and mask it in logs/telemetry. Separate prod vs. debug traces, encrypt at rest/in transit, and implement data retention + subject access deletion workflows.
  62. How do you control generation style and variability?
    Tune temperature (creativity), top_p/top_k (tail trimming), and repetition penalties. Provide few-shot exemplars and style tags. For strict style, use constrained decoding or post-processors. Expose presets per use case (creative vs concise) and A/B the defaults.
  63. Compare quantization options for local models (GPTQ, AWQ, SmoothQuant, FP8).
    GPTQ and AWQ are post-training weight-only methods; AWQ preserves activation outliers better for low-bit inference. SmoothQuant shifts activation range into weights for INT8. FP8 (with hardware support) offers strong throughput with minimal quality loss. Validate on your tasks—quantization sensitivity varies by layer.
  64. How do you distill a large model into a smaller one for edge inference?
    Use supervised distillation (teacher outputs as targets) with task-specific data; add preference or chain-of-thought distillation where allowed. Mix instruction and negative examples, and evaluate on your golden tasks. Consider multi-stage: pre-distill for general ability, then LoRA-adapt per domain.
  65. What’s your strategy for continual learning without catastrophic forgetting?
    Use adapter-based methods (LoRA per domain/tenant) and rehearsal with a small replay buffer. Regularize with EWC/LwF variants when doing full-weight FT. Prefer retrieval (RAG) for freshness and keep adapters narrowly scoped. Evaluate old + new tasks before promoting.
  66. How do you evaluate code or math generations robustly?
    Use execution-based metrics: run generated code/tests in a sandbox and score pass rate; for math, check numeric equality within tolerances. Add unit-test generation prompts and hidden test suites. Penalize flaky nondeterminism and enforce time/memory limits.
  67. How do you safely run a code-interpreter/tool agent?
    Sandbox execution (seccomp/AppArmor/Firejail), mount ephemeral FS, disable network or allow-list egress, and cap CPU/RAM/time. Route IO through typed APIs, scrub outputs, and require confirmations for risky actions. Keep detailed audit logs.
  68. What does high-utilization autoscaling for GPUs look like?
    Use queue + admission control, batch/continuous batching engines (e.g., vLLM), and bin-pack requests by context length. Keep warm pools, pre-load KV caches for common system prompts, and scale with predictive signals (cron load, region). Implement graceful drain/health probes.
  69. How do you design rate limiting and abuse prevention?
    Enforce per-user/tenant quotas, token budgets, and concurrency caps. Add anomaly detection (spikes, scraping patterns), captcha/human checks for UIs, and blocklists. Provide safe error messaging and admin overrides; never leak policy details that help attackers.
  70. Which observability metrics matter most for GenAI services?
    Latency (TTFB, time-to-last token), throughput (tokens/sec), cost per request, cache hit-rate, tool error rate, retrieval recall, and quality proxies (thumbs-up rate, groundedness). Dashboard by model/route and alert on SLO breaches with fast rollback hooks.
  71. How do you curate and deduplicate training/eval data?
    Normalize and de-HTML, dedup with MinHash/LSH or embedding-based near-dup checks, and filter low-quality/NSFW. Keep provenance, licenses, and splits. Guard against contamination: exclude eval overlaps and sensitive corpora; log all transforms for reproducibility.
  72. What are the copyright/licensing concerns when training or retrieving content?
    Respect licenses (CC-BY, CC-BY-NC, proprietary), honor robots/ToS, and maintain provenance. For RAG, return citations; for training, consider opt-out compliance and internal use only where applicable. Consult counsel for scraping/derivative-work risk and DMCA processes.
  73. How do GDPR and the EU AI Act affect GenAI features?
    GDPR: data minimization, lawful basis, DSRs (access/erasure), and processor agreements. EU AI Act: classify risk, perform conformity assessments, maintain logs, and provide transparency; high-risk use cases need rigorous governance. Avoid training on personal data by default.
  74. What is your release management process for models and prompts?
    Use semantic versioning for prompts/models, gated releases with offline + online evals, canary traffic, and instant kill switches. Publish model cards and change logs. Keep rollback artifacts and freeze golden datasets to compare across versions.
  75. List advanced cost-control techniques for GenAI in production.
    Route easy tasks to small models, cache aggressively (request and KV caches), stream early tokens to cut abandon costs, batch requests, quantize/self-host where it’s cheaper, distill large to small, and use mixture-of-experts or router models. Track blended cost per successful task, not per request.
  76. How do you design an evaluation harness to measure hallucinations in a domain-specific QA system?
    Create a gold set with question–answer–evidence triples. Score faithfulness with human labels and automatic checks: evidence overlap, answerability, and contradiction detection. Break out step metrics (retrieval hit@k, rerank precision, groundedness, final correctness) and run per-topic slices to see where hallucinations cluster.
  77. How can a model decide when to abstain and ask for clarification?
    Calibrate selective prediction using entropy/logprob thresholds, retrieval coverage (e.g., no supporting chunk), and tool error signals. Route low-confidence cases to a clarifying prompt or a human. Periodically recalibrate thresholds against labeled holdouts to keep precision/recall of ‘I don’t know’ acceptable.
  78. Tool calling vs. pure generation: when do you choose each?
    Use pure generation for low-risk, subjective, or creative tasks. Use tool calling when accuracy, freshness, or side effects matter (calculators, DB queries, APIs). Wrap tools with schemas and idempotent contracts, log inputs/outputs, and gate tool usage via allow-lists and policies.
  79. How do you prevent infinite loops or thrashing in agentic planners?
    Impose a hard step budget, detect repeated states with hashing, add termination critics, and penalize non-progress in the planner’s reward. Keep an execution graph (DAG) with cycle checks and surface a final fallback answer with partial progress when limits are hit.
  80. What are pros and cons of multi-agent debate or self-consistency?
    Debate/self-consistency improves factuality by aggregating diverse chains, but increases cost and latency. It can also amplify shared biases. Use it selectively (high-stakes queries), cap votes/rounds, and add a verifier that checks final claims against evidence.
  81. How do you layer safety filters without harming useful output?
    Use pre-filters (input policy checks), in-loop guards (tool gating, prompt constraints), and post-filters (response classifiers + redaction). Measure utility loss via shadow traffic and provide safe rewrites instead of hard blocks when possible. Keep per-policy analytics to tune thresholds.
  82. Describe a red-teaming strategy for a GenAI application.
    Blend manual red-team playbooks with automated fuzzing (jailbreak corpora, payload mutation). Cover prompt injection, data exfiltration, PII handling, and tool misuse. Track findings in a taxonomy, add regression tests, and gate releases on passing high-severity scenarios.
  83. How do you handle conflicting evidence from multiple retrieved sources?
    Score source reliability (authority, recency), cluster by stance, and ask the model to reconcile explicitly with citations. Prefer neutral synthesis when conflicts persist and expose uncertainty. Optionally escalate to a human or require a curated source list for critical domains.
  84. What’s a robust approach to large-scale structured extraction from messy documents?
    Use a hybrid pipeline: layout/OCR parsing → structural tagging → LLM extraction with constrained schemas → validation/repair. Add document-type classifiers, template hints, and fuzzy matchers for fields. Maintain per-field accuracy dashboards and human review queues for low-confidence items.
  85. Fine-tuning vs. RAG vs. prompt engineering—how do you choose?
    Prefer RAG when knowledge changes frequently or must be cited; fine-tune when behavior/style must change consistently or you need new skills; prompt engineering when the task is stable and low-risk. Often combine: prompt → RAG → light adapters/LoRA for final polish.
  86. DPO vs. RLHF: what’s the difference and when would you use each?
    RLHF optimizes with a learned reward model; DPO directly optimizes from preference pairs without an explicit reward model. DPO is simpler and stable for instruction tuning; RLHF is more flexible when you need custom reward shaping or tool-use objectives.
  87. How do you avoid data poisoning in online learning or feedback loops?
    Isolate training from production, rate-limit and vet feedback, and require multi-reviewer consensus. Use robust statistics and outlier filters, maintain audit trails, and retrain from clean baselines. Never let unvetted user content directly alter system prompts.
  88. How can you collect product analytics while preserving user privacy?
    Aggregate on device when possible, hash or tokenize IDs, redact PII, and use differential privacy or k-anonymity for sensitive events. Minimize raw log retention, segregate access, and honor deletion requests via data lineage.
  89. Techniques to reduce latency for long-context prompts?
    Use prompt caching, KV-cache reuse, shorter system prompts, compressed summaries, and retrieval to avoid overlong context. Prefer fast small models for pre-steps (routing, retrieval) and stream tokens early to improve perceived latency.
  90. What is KV-cache reuse and what risks does it introduce?
    KV-cache reuse avoids recomputing attention on shared prefixes, improving throughput. Risks include data leakage across sessions and stale or cross-tenant context. Partition caches per user/session, encrypt in memory where possible, and clear on privilege changes.
  91. How do you manage context truncation without losing critical information?
    Summarize older turns into a compact state, keep a fact memory, and use recency-biased retrieval. Pin essential instructions/tools at the top and maintain a strict context budget with automatic pruning. Validate that outputs remain stable across truncations.
  92. What’s a reliable loop for code generation tasks?
    Plan → generate code → run tests in a sandbox → capture errors → self-debug prompt → iterate with a step cap. Keep deterministic tooling, time/memory limits, and redact outputs. Log pass rates and flaky test stats as your core metrics.
  93. How would you build a multimodal RAG system (text + images)?
    Use separate encoders for text and vision with a shared space or late fusion. Index captions/alt-text plus visual embeddings; retrieve both and pass the most relevant combos into a multimodal generator. Keep modality-aware reranking and display cited snippets and crops.
  94. How do you evaluate factual summarization quality at scale?
    Combine automatic faithfulness checks (claim–evidence matching, contradiction detection) with human audits on sampled slices. Track coverage, compression ratio, and groundedness. Penalize unsupported claims, not only fluency.
  95. Design considerations for agents that operate on external business systems (e.g., CRM).
    Use typed tool schemas, dry-run simulators, and idempotent operations with dedupe keys. Require confirmations for destructive actions, implement retries with backoff, and store a signed execution log for audits and rollbacks.
  96. How do you safely roll out prompt/model changes?
    Version prompts/models, run offline evals on golden sets, then do canaries with guardrails and quick rollback. Monitor KPIs (quality, latency, cost, safety hits). Keep feature flags and clearly log which version served each request.
  97. What is prompt version control and why does it matter?
    Treat prompts as code: semantic versions, diffs, owners, tests, and changelogs. It ensures reproducibility, debuggability, and compliance (who changed what/when), and enables fast rollback if metrics regress.
  98. How do you estimate and monitor hallucination rates in production?
    Use weak labels (citation presence, retrieval coverage) and periodic human audits on sampled traffic. Add user feedback signals and downstream correctness proxies (e.g., failed tool calls). Track per-route/tenant, and set alert thresholds.
  99. How do you forecast and control token costs for a GenAI feature?
    Instrument per-stage token usage, model mix, cache hit rates, and abandonment. Set token budgets per request, route easy cases to smaller models, and cap context length. Review blended cost per successful task, not per raw request.
  100. What does an incident response playbook for model regressions include?
    Define triggers (SLO breaches, safety spikes), on-call ownership, snapshot/rollback steps, traffic routing fallbacks, and communication templates. Capture postmortems with root causes (data, infra, prompt), and add regression tests to prevent recurrence.
Tip: For senior-level answers, call out trade-offs (quality vs. latency vs. cost), how you evaluate groundedness/hallucinations, and how you productionize (observability, A/B, rollbacks, and safety).