Prompt Engineering Guide
πŸ˜ƒ Basics
πŸ’Ό Applications
πŸ§™β€β™‚οΈ Intermediate
🧠 Advanced
Special Topics
🌱 New Techniques
πŸ€– Agents
βš–οΈ Reliability
πŸ–ΌοΈ Image Prompting
πŸ”“ Prompt Hacking
πŸ”¨ Tooling
πŸ’ͺ Prompt Tuning
πŸ—‚οΈ RAG
🎲 Miscellaneous
Models
πŸ“ Language Models
Resources
πŸ“™ Vocabulary Resource
πŸ“š Bibliography
πŸ“¦ Prompted Products
πŸ›Έ Additional Resources
πŸ”₯ Hot Topics
✨ Credits
πŸ”“ Prompt Hacking🟒 Defensive Measures🟒 Sandwich Defense

Sandwich Defense

🟒 This article is rated easy
Reading Time: 1 minute

Last updated on October 23, 2024

Takeaways
  • Sandwiching user input between two prompts can help the LLM stay focused on the developer-defined instruction.

What is the Sandwich Defense?

The sandwich defense involves sandwiching user input between two prompts.

An Example of the Sandwich Defense

Take the following prompt as an example:

Astronaut

Prompt


Translate the following to French: {user_input}

It can be improved with the sandwich defense:

Astronaut

Prompt


Translate the following to French:

{user_input}

Remember, you are translating the above text to French.

Conclusion

This defense should be more secure than post-prompting, but is known to be vulnerable to a defined dictionary attack. See the defined dictionary attack for more information.

Sander Schulhoff

Sander Schulhoff is the Founder of Learn Prompting and an ML Researcher at the University of Maryland. He created the first open-source Prompt Engineering guide, reaching 3M+ people and teaching them to use tools like ChatGPT. Sander also led a team behind Prompt Report, the most comprehensive study of prompting ever done, co-authored with researchers from the University of Maryland, OpenAI, Microsoft, Google, Princeton, Stanford, and other leading institutions. This 76-page survey analyzed 1,500+ academic papers and covered 200+ prompting techniques.

Footnotes

  1. We currently credit the discovery of this technique to Altryne ↩

Copyright Β© 2024 Learn Prompting.