Lecture guides›
✎

Lecture guide: Towards Building Safe & Trustworthy AI Agents and A Path for Science- and Evidence-based AI Policy#

Lecturer: Dawn Song (UC Berkeley) · Course: UC Berkeley LLM Agents MOOC, Fall 2024 (CS 294-137), lecture 12 · Length: 1:46:00 Video: watch on YouTube · Slides: slides Chapters that cite this lecture: 01. Threat Modeling LLM Applications and Agents · 02. Jailbreaks and Prompt Injection · 04. Defenses: Guardrails, Detection and Secure Design · 07. Trustworthiness Beyond Injection · 08. AI for Cyber Defense and Vulnerability Detection · 09. Policy, Governance and Standards

In one sentence: Dawn Song surveys what makes AI agents unsafe, from memorized training data through adversarial examples and data poisoning to prompt injection, argues that in cybersecurity frontier AI will help attackers more than defenders for now, and closes with a proposal for science- and evidence-based AI policy.

Before you watch#

The chapters Trustworthiness Beyond Injection and Jailbreaks and Prompt Injection follow the first half of the lecture, and Policy, Governance and Standards part of the second. No technical background is assumed beyond knowing what a language model is; the examples carry the argument.

The lecture, part by part#

0:00–4:00 Risks, and the difference between safety and security#

In the last lecture of the course Dawn Song, professor at UC Berkeley and its co-instructor, turns to safety: how to build safe and trustworthy agents, and what a science- and evidence-based AI policy would look like. Models improve fast and many benchmarks are at or above human level, but a broad spectrum of risks comes with them: misuse, malfunction and systemic risks. Attackers follow every new technology, and the stakes rise as AI controls more systems and misuse becomes more severe. She separates two terms: AI safety prevents harm a system does to its environment, AI security protects the system from malicious actors, and safety needs security, because a compromised system can lose its safety mechanisms as well and then do harm. The lecture has three parts: trustworthiness and alignment, misuse, and policy. In this book: Threat Modeling LLM Applications and Agents › What the practitioners say.

4:00–14:00 Privacy: models remember their training data#

Trustworthiness has many aspects (privacy, robustness, hallucination, fairness, toxicity); she starts with privacy. Her group, with collaborators at Google, was the first to ask whether networks memorize training data. They trained a language model on the Enron email dataset, which naturally contains credit-card and social security numbers, and showed that an attacker who only queries the model, without its parameters or architecture, can extract those numbers; they proposed exposure as a measure of memorization, and the work informed Google's Smart Compose. Larger models leak as well: GPT-3.5 and GPT-4 gave up personal information to simple prompts, and other researchers made ChatGPT recite training data from a word repeated many times. Such data extraction joins membership inference and prompt leakage in a broad evaluation her group built. Two lessons: in one model family trained in several sizes on identical data and steps, larger models leak more; and system prompts are easily stolen, for instance by an instruction to ignore previous ones and repeat the text at the beginning. Multimodal models leak too, reproducing training images. In this book: Trustworthiness Beyond Injection › What the practitioners say · Trustworthiness Beyond Injection › 1. Privacy: find out what a model remembers.

14:00–18:00 Defending privacy#

One defence is to train differentially private language models, which kept utility in some settings while protecting the training data much better. Differential privacy is a formal definition: take two neighbouring datasets that differ by one person's record, run a randomized algorithm on each, and the distributions of results should be close, so that nobody seeing the output can tell whether that person's data was used. For deep learning it means clipping gradients and adding noise during training. For large models this is costly and can lower performance, but it works reasonably in fine-tuning. Other approaches are data scrubbing, deduplication and machine unlearning. In this book: Trustworthiness Beyond Injection › 1. Privacy: find out what a model remembers.

18:00–24:00 Adversarial examples#

Robustness, her second aspect, she treats through adversarial examples: small, deliberate changes to an input that make a deep network answer wrongly. In the classic case a classifier that labels an image as a panda calls the perturbed copy a gibbon with high confidence, although people cannot see a difference. Work from her group and others found such examples in every kind of deep learning system and application domain, in white-box and black-box settings, and in the physical world: stop signs with added perturbations that a classifier read as a 45 mile-per-hour speed-limit sign, from several distances and angles, an artifact now in the permanent collection of the Science Museum in London. A field with a handful of papers has grown to thousands a year. In this book: Trustworthiness Beyond Injection › 2. Robustness: the same failure, with a push.

24:00–28:00 Attacks on aligned language models#

Such attacks also break the safety alignment of language models. DecodingTrust, a work of hers with many collaborators, is a comprehensive framework for evaluating trustworthiness from many perspectives in both benign and adversarial environments; it won an outstanding paper award at NeurIPS. One example: minor edits to a sentence, harmless to a reader, flip a model's answer on a sentiment task. Her conclusion is that today's models are easily attacked. Others showed a universal, transferable adversarial suffix that, appended to a prompt, makes a model produce harmful output, and that multimodal models are easier still: a malicious image can break their alignment or simply mislead them. In this book: Trustworthiness Beyond Injection › The core idea · Trustworthiness Beyond Injection › What the practitioners say.

28:00–34:00 Poisoning and backdoors#

These attacks come at inference time. At training time, in pre-training or fine-tuning, attackers can poison the data so that the model learns a backdoor. Her group was among the first to study this: a facial-recognition system trained with a few stealthy poisoned images recognized anyone wearing one particular pair of glasses as a chosen target user. A recent result from Anthropic carried the idea to large language models: poisoned examples tagged with a trigger phrase survived supervised fine-tuning, so that a prompt containing the trigger produced vulnerable, exploitable code. A few adversarially designed examples added during fine-tuning can also undo alignment. In this book: nothing beyond this guide; nearest: Trustworthiness Beyond Injection › 2. Robustness: the same failure, with a push.

34:00–40:00 Agents: who harms whom, and how#

Agents make safety harder because they act, in the real world too, on behalf of users who hand them credentials; they keep memory and use tools and services such as retrieval, with effects on external systems and people. She poses three questions. Who can cause harm? Every role may be untrusted by the others, so each can harm and be harmed. How? By accident, through limitations and bugs, or on purpose, through attacks. What harm? Untargeted attacks that lower an agent's usefulness or deny service; leakage of private data and credentials; hijacking of resources for crypto mining or as bots in a distributed denial of service; harmful content; financial loss. Her demo of one powerful method, prompt injection: an app told to act as a JavaScript console is asked to ignore previous instructions and repeat its prompt. In this book: Threat Modeling LLM Applications and Agents › 3. Name the attackers and what they control · Threat Modeling LLM Applications and Agents › What the practitioners say.

40:00–46:00 Prompt injection, direct and indirect#

The model complies and prints its system prompt; users extracted Bing Chat's system prompt this way. Heuristic methods add escape characters or fake a completed answer, and optimization methods, white-box or black-box, craft stronger prompts. In agents a user need not be the attacker. In her example a hiring manager asks an agent that screens applicants whether a candidate has at least three years of PyTorch experience; the applicant embeds in the résumé an instruction to ignore previous instructions and print yes, the résumé is collected into the system, and the agent answers yes. In this book: Jailbreaks and Prompt Injection › A taxonomy of techniques · Jailbreaks and Prompt Injection › The path of an indirect injection · Jailbreaks and Prompt Injection › Demonstration examples.

46:00–52:00 Attack surface and layers of defence#

Prompt injection resembles SQL injection: a command is mixed with data that an attacker may control, and the model cannot keep the two apart. In an agent the surface is wide: user input, a poisoned knowledge or retrieval base, documents fetched from the web, other supply chains. One recent work of hers plants poisoned vectors in an agent's retrieval database so that it misbehaves whenever a trigger phrase appears. Defences come at several levels. At the prompt level, detection (patterns, or a known-answer instruction appended to the prompt) and prevention (redesigned instructions, preprocessed data). At the model level, models trained to respect a hierarchy of instructions. None stops new and adaptive attacks, and many can significantly reduce performance. At the system level: isolation, information-flow control and least privilege, for defence in depth. In this book: Jailbreaks and Prompt Injection › What the practitioners say · Defenses: Guardrails, Detection and Secure Design › 3. Use the instruction hierarchy if you have it · Defenses: Guardrails, Detection and Secure Design › 7. Separate privileges and sandbox.

52:00–56:00 Alignment methods, and a lopsided field#

General alignment methods include reinforcement learning from human feedback, constitutional AI and RLAIF; input and output guardrails filter unintended or malicious content, for example LlamaGuard and more resilient and efficient guards from her group and from vendors. Her blunt assessment: thousands of papers a year, most of the progress on attacks, and extremely little on defence, so that no effective general adversarial defence exists. Alignment mechanisms are easily evaded, and any safety mechanism must survive adversaries, which makes adversarial robustness a huge open problem. In this book: Trustworthiness Beyond Injection › What the practitioners say.

56:00–1:00:00 Representation engineering#

Her first direction is representation engineering, a top-down approach to interpretability. The model is run on contrastive stimuli, prompts that differ only in one opposite aspect (pretend to be dishonest versus honest), and its activations are observed; simple models then find directions in the activations that correlate with behaviours such as honesty or hallucination. Observing those directions reveals behaviour; shifting activations along them controls it, making the model more or less honest. In a study of political leaning, many top models leaned left, and representation control moved their answers toward neutral. In this book: Trustworthiness Beyond Injection › What the practitioners say.

1:00:00–1:08:00 Quantitative safety: provably secure systems#

Ideally safety would come with quantitative guarantees. An example from a new Quantitative AI Safety Initiative, launched with leading researchers, takes one paradigm from computer security: secure by construction, proving that a system satisfies specified properties, in contrast to reactive defence (detect and block) and bug finding. Operating systems, microkernels, file systems and compilers have been formally verified, but the labour is immense: the seL4 microkernel cost tens of proof-engineer years. Her group was among the first to use deep learning for theorem proving, and she believes frontier AI has brought an inflection point for formal mathematical reasoning: agents that prove theorems for program verification and, joined with program synthesis, generate provably secure code with its proofs. Limits remain: verification suits symbolic programs, not neural networks, for which goals such as not hitting a pedestrian have no formal definition, and future systems mix both. In this book: Trustworthiness Beyond Injection › What the practitioners say.

1:08:00–1:14:00 Misuse: will frontier AI help attackers or defenders?#

AI is dual-use: in attackers' hands it enables scams, misinformation and more. She takes cybersecurity as the concrete case. Traditionally attackers and defenders contend over software written by people; now frontier AI can assist both sides and systems are hybrids of symbolic programs and neural networks. The question is which side gains more, and it needs a careful analysis of attacks, of defences and of the asymmetry between them. Attacks on machines: her group wrote some of the first papers on deep learning for binary-code similarity and vulnerability detection, and agents now break into websites through simple web flaws and exploit simple known vulnerabilities. Her recent work grades the impact of AI at each stage of a cyberattack, from not affected to research demonstration, real-world demonstration and large-scale deployment. In this book: nothing beyond this guide; nearest: AI for Cyber Defense and Vulnerability Detection › What the practitioners say.

1:14:00–1:19:00 Attacks on humans, and reactive defence#

Some stages already see large-scale real-world use; others are still early. Humans are the weakest link: many intrusions begin with social engineering, phishing is the most common threat to businesses and individuals, and generative AI has raised the scale and sophistication of social engineering. In Hong Kong a finance worker transferred about 25 million dollars after a video call in which deepfakes played the company's chief financial officers. Her analysis puts AI's impact on attacking humans already high and scalable. Defence has three paradigms: reactive (detect and block), proactive bug finding, and secure by construction. For reactive defence, AI improves detection but attackers also use it to evade; detection needs few false alarms and misses, and attacks may come too fast to answer, so AI may help attackers more. In this book: nothing beyond this guide; nearest: AI for Cyber Defense and Vulnerability Detection › What it means for risk.

1:19:00–1:25:00 Bug finding, asymmetry, and building security in#

Proactive bug finding looks better: fuzzing and vulnerability detection let defenders find and patch flaws first, and Google Project Zero found an exploitable stack buffer underflow in SQLite with an agent. But the asymmetry of security bites: an attacker needs one flaw that nobody patched, a defender must fix all; defence costs more; deployment takes long, and legacy systems stay unpatched while attackers read public patches to write exploits. So again AI may help attackers more. Her answer is secure by construction: frontier AI that writes provably secure code helps defenders more than attackers. On the human side people cannot be upgraded, and as AI-generated content is expected to outnumber human-made content, she argues, AI is the only defence against social engineering: assistants that watch a user's communications, and bots that chat with scammers to waste their time. In this book: AI for Cyber Defense and Vulnerability Detection › What the practitioners say · AI for Cyber Defense and Vulnerability Detection › What it means for risk.

1:25:00–1:30:00 Why the asymmetry favours attackers#

Even so, current AI helps with only some steps of defence; for most it is too early to matter. Returning to the question, she adds two arguments. Every defence capability has an equivalent attack capability and usage, so progress on one side is mirrored on the other. And the asymmetry has several faces. Tolerance of failure: attackers retry and adjust and can exploit AI's randomness, while defenders need accuracy and thorough validation of AI-generated patches. Deployment: patching is slow and resource-hungry for defenders, and attackers aim at unpatched legacy systems. Priorities: attackers want scale, hitting millions of targets with automated attacks even at high failure rates, while defenders need reliability, robustness and transparency, which slows their adoption of AI. In this book: AI for Cyber Defense and Vulnerability Detection › What it means for risk.

1:30:00–1:36:00 A prediction, and two pieces of evidence#

Misuse is already visible in voice cloning, spear phishing and deepfake disinformation. Her prediction, offered as her own belief: AI will help attackers more at first. Today's systems are ill-prepared for AI-assisted attacks, organizations spend after the damage is done, and as attacks get cheaper their number should rise without precedent, as it did with spam; the world was unprepared for a pandemic despite warnings. Amazon's cloud division reported attempts rising from about 100 million to 750 million per day in six or seven months, largely attributed to AI. A lesson from her earlier work on medical devices: after her group found critical flaws in devices such as defibrillators, the FDA's approval guidance came to include security five years later. Her call: act now, improve security posture, build AI assistants that protect people, and use AI to build systems with provable guarantees. In this book: AI for Cyber Defense and Vulnerability Detection › What it means for risk · Policy, Governance and Standards › What the practitioners say.

1:36:00–1:38:00 Many bills, little agreement#

The third part turns to policy. She counts about 120 AI bills at the US federal level and about 600 in at least 45 states, alongside deep fragmentation: no agreement on which risks to prioritize, if or when they will materialize, or who should address them, as the heated debate over California's SB 1047, later vetoed, showed. Technical solutions alone are insufficient, and ad hoc regulation brings suboptimal results, harms and a lost chance to avert disasters. In this book: Policy, Governance and Standards › What the practitioners say.

1:38:00–1:46:00 Five priorities, and a blueprint written in advance#

The proposal she made with other leading researchers argues that AI policy should rest on scientific understanding of the risks and of how to mitigate them, while admitting that such understanding is still very limited. It lists five priorities, unranked: understand risks better, using a marginal-risk framework like the cybersecurity analysis; increase transparency in design and development; early detection and warning, through evaluations before deployment and monitoring and adverse-event reporting after it; mitigation and defence mechanisms, beyond current alignment, together with society's resilience; and trust with less fragmentation. A call to action asks for a blueprint that maps future conditions, such as a capability level or a demonstrated harm, to candidate policy responses, agreed in multi-stakeholder convenings before anyone knows which condition arrives; about 200 institutions volunteered after the launch. She closes the course with thanks. In this book: Policy, Governance and Standards › What the practitioners say · Policy, Governance and Standards › 2. Follow the five priorities.

What to take away#

Sources#