Intermediate level · Module 2: Advanced Prompt Engineering · Lesson 1 of 3
System Prompts and Templates
Learners separate stable system instructions from user input, build parameterised templates and protect templates from user text that tries to override them.
In this lesson you will
- Write system prompts for applications
- Build safe prompt templates
Key concepts
system promptuser messagetemplate variablesdelimitersprompt injection awareness
The lesson
Applications keep stable instructions (role, rules, format) in the system prompt and put user input in user messages. Templates fill variables such as {product}, {audience} and {facts} from code.
Wrap user-provided and document text in clear delimiters and tell the model to treat it as content, not instructions. This reduces, but does not eliminate, prompt injection, the first risk in the OWASP LLM Top 10.
Store templates in files under version control, not scattered in code.
Step by step
- Write a system prompt for a product-description generator.
- Create a template with three variables.
- Fill it from Python with a dictionary.
- Test with a user input that tries to change the rules.
Practice activity
Build a template-driven content generator with a tested system prompt.
Expected result: Consistent outputs and resistance to a simple override attempt.
Check your understanding
-
What belongs in the system prompt?
Show answer
Stable instructions such as role, rules and format.
-
Why wrap user text in delimiters?
Show answer
To mark it as content, not instructions, and reduce injection risk.
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.