# 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.

- URL: https://dmxsf.com/en/wiki/safety/
- [DMXSF](https://dmxsf.com/en/about/)
- Updated: 2026-11-15

## 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](https://dmxsf.com/en/wiki/evaluation/) chapter first; the principles of preference optimization and safety training are in [Post-training and Alignment](https://dmxsf.com/en/wiki/post-training/).

[Chapter labs on GitHub](https://github.com/dmxsf/dmxsf/tree/main/labs/safety)
