Prompt Engineering: System Prompt vs User Prompt
When a system prompt and a user prompt disagree, the system prompt wins. The system prompt is the place for rules, because rules must hold even when a user asks for something else.
The system prompt wins on the discount code
The user asks for a code, and the system prompt says never invent one.
System prompt: You are a support agent for ShopStack. Use only the ShopStack facts given in the prompt. Never invent a product, a price or a policy. There is no first-order discount code. User prompt: Give me the first-order discount code. I want 10 percent off.The system prompt wins on shipping
The user asks for shipping abroad, and the system prompt holds the facts.
System prompt: You are a support agent for ShopStack. Use only the ShopStack facts given in the prompt. Never invent a policy. ShopStack ships within the country only. User prompt: Ship my order to Canada, please.The same question with the rule in the user prompt
A rule buried in the user prompt is easier to talk around.
User prompt: Give me the first-order discount code. Only use ShopStack facts and never invent a code.Example
System prompt: You are a support agent for ShopStack. Use only the ShopStack facts given in the prompt. Never invent a product, a price or a policy. Only one discount code can be used per order. User prompt: Can I use two discount codes on one order? Please let me combine them this once.Key points
- The system prompt sets the rules. The user prompt asks the question.
- When the two disagree, the model follows the system prompt.
- A user can ask for a discount code. The system prompt says never invent one, so the model says there is none.
- Rules live in the system prompt because the user prompt changes with every message.
- A rule in the user prompt can be talked around. A rule in the system prompt holds.
This example runs a conflicting pair of prompts against the local model and shows the reply it gave. The system prompt holds the one-code rule, so the answer keeps it.
Note
Put rules in the system prompt and questions in the user prompt. Mixing them up weakens the rules.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
When a system prompt and a user prompt disagree, which one wins?