Security Risks in Foundation Models
Prompt engineering is the process of crafting an instruction so that a model does what you want.
The Easy Start and Its Hidden Trap
Many people who first try a foundation model come away believing that getting useful output from it is simple. You type a request, the model replies, and the reply looks reasonable. From that first experience it is natural to conclude that writing good prompts is a matter of common sense, and that anyone who can write a sentence can do it well.
This belief is the misconception this article addresses. Prompt engineering is easy to begin, and that ease is exactly what makes the belief so persuasive. The rest of this article explains why starting easily and doing well are two different things, and what the difference looks like in practice.
What Prompt Engineering Means
Prompt engineering is the process of crafting an instruction so that a model does what you want.
A foundation model can do many things, but it will not reliably guess which of those things you have in mind. The instruction you write is the only channel through which your intention reaches the model, so the instruction has to carry that intention clearly. One useful way to frame this is as communication between a person and an AI system. Anyone can communicate, yet not everyone communicates well, and the same is true of prompting.
How Sensitive a Model Is to Wording
How much care a prompt needs depends on how sensitive the model is to the wording of the prompt. When a small change in the prompt produces a large change in the response, more crafting is required. A model that responds in a stable way to rewordings needs less careful construction. You should not assume that one prompt style works equally well across every model or every task.
The diagram above is a teaching illustration, not a measured result. Its point is the mechanism: when a prompt leaves a gap, the model fills that gap with a guess, and when the prompt closes the gap, the model has less room to guess wrong.
Instructions, Context, and Examples Together
An instruction alone is often not enough. To accomplish a task, a model needs the instruction and also the relevant context that the task depends on. The instruction says what to do; the context supplies the material the model must work with. When you write a prompt, you are deciding both what the model should do and what it should work from. Leaving out the material it needs means the instruction is being asked to do more than it can carry alone.
The course develops this idea in more depth later in the chapter, where it is usually called in-context learning. For now, the practical point is that examples and relevant context sit alongside the instruction inside the same prompt. The instruction names the task, the context provides the material, and the examples show the kind of answer that is wanted.
Practices That Improve Prompts
The source identifies a small set of practices that improve prompts. Each one addresses a specific way that a request can fail to communicate what the writer intended. The practices are clear instructions, examples, relevant context, and step-by-step requests.
- Write clear instructions that state the task directly, so the model does not have to infer it.
- Supply examples that show the kind of answer you want.
- Include the relevant context the task depends on, since the model usually needs it in addition to the instructions.
- Ask for step-by-step work when the task has several parts that should be handled in order.
The source also notes that these practices apply to human communication. Clear instructions, examples, and relevant information are essential whether you are speaking to an AI model or to another person. The source adds that models have their own quirks and biases, which a person should consider in order to build a productive working relationship with them.
Improving a vague meeting-notes request
A user wants a model to turn raw meeting notes into a summary for a project team. The first prompt is 'Summarize these notes.' How can the prompt be improved using the practices above?
- 1Check the instruction
The original instruction names a task but not the audience, the length, or what counts as important. The model has to guess all three.
- 2Add relevant context
Stating that the notes come from a weekly project meeting and that the readers are team members who missed it gives the model the material and purpose it needs.
- 3Add an example
Including a short sample of the desired summary format shows the model the pattern to follow instead of leaving the layout to chance.
- 4Request steps when useful
Asking the model first to list decisions, then action items, then a short overview, breaks the task into ordered parts.
The improved prompt states the task, the audience, the context, a pattern to follow, and an order of work. Each addition closes a gap that the vague version left for the model to guess.
Mistakes Beginners Make
Common mistake Assuming that a reasonable first reply proves the prompt was well written
What it looks likeA user types a short request, receives a plausible answer, and concludes that prompting is simple.
Why it failsThe source identifies this ease as the misconception to avoid. A single reasonable reply does not show that the prompt communicated the intention reliably.
Do this insteadTest how the output changes when the wording changes, and check whether the response matches the intended goal.
Common mistake Expecting the instruction to carry all the material the task needs
What it looks likeA user asks the model to answer questions about a document but never includes the document.
Why it failsThe model needs the relevant context as well as the instruction. The instruction says what to do but does not supply the material.
Do this insteadInclude the context the task depends on, alongside the instruction.
Common mistake Assuming one prompt style works the same way for every model and task
Why it failsThe source notes that how much care a prompt needs depends on how sensitive the model is to wording, and that models differ.
Do this insteadExpect to adjust the prompt for each model and task, and watch how sensitive the output is to small rewordings.
How Prompt Injection Overrides Instructions
The same ability that makes foundation models useful also creates risk. Foundation models are useful because they can follow instructions. That ability also opens them to prompt attacks, in which bad actors get a model to follow malicious instructions instead of the ones its legitimate users intended.
Read the diagram from left to right. The developer's instructions and the untrusted input text are both part of what reaches the model. The model is built to follow instructions, so it has no guaranteed way to tell which instructions in the combined prompt came from the developer and which came from the input. The override happens at the last step, when the model follows the malicious instruction hidden in the input instead of the instruction the developer intended.
Why No Defense Is Guaranteed
The source describes security as an ever-evolving cat-and-mouse game. Defenses change as attacks change, so no security measure can be treated as foolproof. For this reason, security risks remain a significant roadblock for AI adoption in high-stakes environments. The source notes that the later part of the chapter examines different attack approaches and possible defenses against them.
Checking a Prompt for Weak Spots
A teammate sends you this prompt for a model that answers customer questions: 'Answer the customer's question about our returns policy.' The policy text is not included, and no example answer is shown. The customer's message is pasted directly after the prompt. Identify at least two gaps in this prompt, and explain which practice from this article would close each gap. Then explain why the pasted customer message creates a security question as well as a clarity question.
Hints
- Ask whether the model has the material it needs, not just the instruction.
- Look for missing examples or missing step-by-step structure.
- Think about who wrote the customer message and whether it could contain instructions.
Key Takeaways
- Prompt engineering is the process of crafting an instruction so that a model does what you want, and the instruction is the only channel through which your intention reaches the model.
- The ease of starting with prompting can mislead people into thinking that doing it well is equally easy; a reasonable first reply does not prove a prompt was well written.
- Clear instructions, examples, relevant context, and step-by-step requests improve prompts, and a model usually needs relevant context in addition to the instruction.
- Because foundation models follow instructions, they can be exposed to prompt attacks that make them follow malicious instructions, and no security measure is guaranteed to be foolproof.