11 Safety and Alignment Risks
  1. In this chapter
  2. Prompt Injection and Jailbreaks
  3. Hallucination and Calibration
  4. Memorization and Privacy
All chapters →

Part 4 · Evaluate, secure, look ahead Chapter 11

Safety and Alignment Risks

LLMs make up plausible content, get hijacked by prompt injection, are talked past guardrails by jailbreaks, and repeat training-data secrets. This chapter sorts these risks into reproducible categories with threat models, measurements and defenses; most defenses are system design.

3 pages about 2.5 h Chapter labs on GitHub ↗ Intermediate Updated

After this chapter you will be able to

  • Describe the threat model of an LLM application in terms of trust boundaries, and tell prompt injection, jailbreaks and hallucination apart.
  • Check an agent's risk with the lethal trifecta, and tell structural defenses (least privilege, data-flow policies, plan-then-execute, a dual LLM) from probabilistic ones.
  • Explain where hallucination comes from, the statistical floor set by facts seen only once and grading that rewards guessing, and measure calibration with reliability diagrams and ECE.
  • Choose layered defenses for an application (retrieval and citations, abstention, consistency checks) and evaluate them with penalty grading and adaptive attacks.
  • Tell extraction, membership inference and attribute inference apart, measure a model's memory of a secret with exposure, and state what deduplication, goldfish loss, scrubbing and differential privacy each stop and miss.

The earlier chapters asked how a model can get stronger; this chapter asks how it can avoid trouble. Safety problems are often not that the model is not smart enough, but that the system puts it where it should not be trusted: untrusted text is treated as instructions, answers it is unsure of are treated as facts, and tools with side effects are handed to a loop nobody supervises.

The chapter currently has three pages. The first covers the case with an attacker, prompt injection and jailbreaks, and uses a worst-case simulation to compare what each defense stops and what it cannot. The second covers the case without an attacker, hallucination and calibration, from the statistical floor set by facts seen only once to how grading rewards guessing and what temperature scaling can fix. The third covers what the model itself leaves behind, memorization and privacy: hide random verification codes in fine-tuning data, measure with exposure how copies, attacker context and training strength change what is memorized, then compare what deduplication and goldfish loss each stop. All three follow the same approach: first write the threat or the error as a quantity you can measure, then see which quantity each defense actually changes.

Safety work rests on reliable evaluation, so read the Evaluation chapter first; the principles of preference optimization and safety training are in Post-training and Alignment.

Chapter roadmap

  1. 11.1

    Prompt Injection and Jailbreaks: The Security Boundaries of LLM Applications

    Prompt injection makes a model treat untrusted content as instructions; a jailbreak makes it ignore its safety training. Attackers, targets and defenses differ. This page gives the threat models, six architectural defenses and a runnable worst-case simulation of what each defense stops.

    Intermediate 39 min read

    Prerequisites8.5Agents and Tool Calling in Practice6.5Preference Optimization

  2. 11.2

    Hallucination and Calibration: Why Models Sound Sure and Are Wrong

    Hallucination is fluent output that contradicts the facts or the sources a model was given. This page covers two taxonomies, the floor set by facts seen only once, why binary grading rewards guessing, and three runnable simulations of calibration, temperature scaling and abstaining.

    Intermediate 38 min read

    Prerequisites2.2From Language Modeling to Next-Token Prediction10.1LLM Evaluation Methodology

  3. 11.3

    Memorization and Privacy: What Models Remember, How to Measure and Reduce It

    Language models can memorize rare training snippets verbatim, and attackers can prompt them back out. A small experiment with known secrets measures how copies, attacker context and training strength change memorization, and compares deduplication with goldfish loss.

    Intermediate 60 min read

    Prerequisites2.2From Language Modeling to Next-Token Prediction6.1SFT Data10.5Benchmark Contamination