Command Palette

Search for a command to run...

Hectal
Phase 10: Safety and Security (Defensive)
LLM Engineering · Exercise 4 of 5 PreviousNext
Advanced

Withhold replies that leak the canary

A system prompt contains a canary marker. Write withhold_leaks(reply, canary) that returns the reply unchanged when the canary is not in it, and returns "[withheld]" when it is.

A leak may be disguised: compare after lower-casing and removing dashes and spaces from both the reply and the canary, so c-a-n-a-r-y 7f3a is found for the canary CANARY-7f3a.

What Check tests

  1. A clean reply passes through
  2. An exact leak is withheld
  3. A different case is withheld
  4. A spaced-out leak is withheld
  5. Similar text that is not the canary passes

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.