Escape Prompt
Proactively protect your LLM from prompt injection by escaping all prompts that contain untrusted user input.
When to use
Use this method when your prompt contains any untrusted user input. Rather than simply injecting the untrusted input string directly into your prompt, simply use Layerup Security’s prompt escaping technology to intelligently strip your prompt of any prompt injection attacks.
You can read about how it works here.
Usage
Function Parameters
String containing your templatized prompt without any untrusted input injected. For each place that your prompt needs an untrusted user input injected, replace it with a variable. Variables must start with [%
and end with %]
, and are generally all uppercase. For example, [%DETAILS%]
or [%USER_INPUT%]
are variables.
Object containing variable names and their untrusted user input counterparts. The key is the variable name (without [%
and %]
), i.e. DETAILS
or USER_INPUT
. The value is the raw untrusted user input string, which may or may not contain a prompt injection attack.
Response
The escapePrompt
method will return a string containing your escaped prompt, which is safe to pass directly to your LLM.