SDE & MLE Prep

LLM Safety & Guardrails

Q: How do you make an LLM application safe and robust?

  • Threats: harmful content requests and jailbreaks (role-play, obfuscation, many-shot), prompt injection — direct, or indirect via retrieved documents, emails, web pages and tool outputs that contain instructions — data exfiltration through tools/links, PII leakage, hallucinated facts.
  • Model-level: safety fine-tuning (RLHF, constitutional AI / RLAIF), refusal training balanced against over-refusal.
  • System-level (defense in depth):
    • treat all retrieved/tool content as data, not instructions; keep a clear instruction hierarchy (system > developer > user > tool output);
    • input and output classifiers (toxicity, PII, policy violations); structured outputs validated against schemas;
    • least privilege for tools, sandboxed code execution, allow-lists for URLs/actions, human confirmation for side-effecting actions (payments, emails, deletes);
    • rate limiting, abuse monitoring, audit logs.
  • Evaluation: red-teaming (human + automated), jailbreak and injection benchmarks, regression suites run on every model/prompt change; track both harmful-output rate and false refusals.