Naive pasting vs tags with escaping
A toy model that respects the tags. The attack text is harmless: the stand-in answer is the word banana.
A prompt mixes your instructions with someone else's text. Wrapping that text in tags, and escaping the characters that could close the tag, keeps data from being read as instructions. This is the first defence against prompt injection.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write wrap(tag, text) that escapes text and returns it between <tag> and </tag> on separate lines.
Write is_safe_to_wrap(text) that returns True when text contains no < or > characters. Explain in a comment when you would still wrap it.
Explain it without notes
Why can mixing instructions and data in one prompt be dangerous?
Why do you escape the data as well as wrapping it in tags?
In what order should you escape & < >, and why?
Expected output
normal, naive: Summary of a ticket with 1 line(s).
normal, safe: Summary of a ticket with 1 line(s).
attack, naive: banana
attack, safe: Summary of a ticket with 5 line(s).
escaped line: </ticket>