All courses LLM apps

AI Security: Hack and Harden an LLM App

Advanced

Prompt injection, tool permissions, access control and data leaks, one attack at a time.

Advanced 8 lessons 24 lab exercises Certificate Updated

You build

A command-line helpdesk assistant for a made-up online shop that answers from help articles, looks up orders and issues refunds for the signed-in customer, shipped deliberately vulnerable and hardened one attack at a time, with a suite of saved attacks that proves each defence.

You need

  • Python: functions, classes, dictionaries, exceptions, reading files and running a program from a terminal
  • Calling a language model from Python: messages and the system prompt, and tool calling, where the model asks for a function and your code runs it and returns the result (the course Build Your First LLM App in Python is one way to get these)

To build it on your own machine

This is optional and comes with a plan. The course pack brings the starting files, a ready container and a check for every lesson. You need only Docker and git, plus your own AI coding agent if you want a tutor.

What you learn

Assume the model will be fooled, and build the app so that it does not matter

You are handed a small helpdesk assistant that answers customers, looks up orders and issues refunds, and it is full of holes. In each lesson you attack it one way, watch the attack work, and add the check in code that stops it, even when the model is completely fooled. You finish with an assistant whose rules no conversation can talk around and a suite of saved attacks that you run before every change. You have already built an app that calls a model with tools; you need no security background.

  • Why Assistants Can Be Fooled. A model receives instructions and data as one stream of text and has no built-in way to tell them apart. You see what that means in practice: a customer who overrides the rules by typing, and a document that gives orders to the assistant that reads it.
  • Rules and Access Live in Code. A system prompt is not a security control. Limits, identity and permission checks move out of the prompt and into the code that runs each tool, where a conversation cannot reach them and the model is never the one that decides.
  • Limiting What an Attack Can Reach. Prompt injection has no complete fix, so the design has to hold when one gets through: narrow tools with the least access that works, untrusted content labelled as data, and a confirmation from the user before anything consequential happens.
  • Nothing Sensitive In, Nothing Harmful Out. Everything in a model's context can be repeated, and everything it writes can be shaped by an attacker. You keep secrets and other people's data out of the context, and check each reply before it leaves.
  • Proof That Repeats. An attack on a live model works one time and fails the next. Saved attacks replayed against a stand-in model that always falls for them turn each defence into a test that gives the same answer on every run, and one command runs them all before a change ships.

Lessons

Where it fits

Course 8 of 8 on the AI Engineer path.

How our courses are made Report a mistake