|
| 1 | +--- |
| 2 | +title: "Prompt Security" |
| 3 | +description: "Prompt Security detects and protects against prompt injection, sensitive data exposure, and other AI security threats." |
| 4 | +--- |
| 5 | + |
| 6 | +[Prompt Security](https://www.prompt.security/solutions/employees) provides advanced protection for your AI applications against various security threats including prompt injections and sensitive data exposure, helping ensure safe interactions with LLMs. |
| 7 | + |
| 8 | +To get started with Prompt Security, visit their website: |
| 9 | +<Card title="Get Started with Prompt Security" href="https://www.prompt.security/solutions/employees" /> |
| 10 | + |
| 11 | +## Using Prompt Security with Portkey |
| 12 | + |
| 13 | +### 1. Add Prompt Security Credentials to Portkey |
| 14 | + |
| 15 | +* Click on the `Admin Settings` button on Sidebar |
| 16 | +* Navigate to `Plugins` tab under Organisation Settings |
| 17 | +* Click on the edit button for the Prompt Security integration |
| 18 | +* Add your Prompt Security API Key and API Domain (obtain these from your Prompt Security account) |
| 19 | + |
| 20 | +### 2. Add Prompt Security's Guardrail Check |
| 21 | + |
| 22 | +* Navigate to the `Guardrails` page and click the `Create` button |
| 23 | +* Search for either "Protect Prompt" or "Protect Response" depending on your needs and click `Add` |
| 24 | +* Set any `actions` you want on your check, and create the Guardrail! |
| 25 | + |
| 26 | +<Note> |
| 27 | + Guardrail Actions allow you to orchestrate your guardrails logic. You can learn more about them [here](/product/guardrails#there-are-6-types-of-guardrail-actions) |
| 28 | +</Note> |
| 29 | + |
| 30 | +| Check Name | Description | Parameters | Supported Hooks | |
| 31 | +|------------|-------------|------------|-----------------| |
| 32 | +| Protect Prompt | Protect a user prompt before it is sent to the LLM | None | `beforeRequestHook` | |
| 33 | +| Protect Response | Protect a LLM response before it is sent to the user | None | `afterRequestHook` | |
| 34 | + |
| 35 | +### 3. Add Guardrail ID to a Config and Make Your Request |
| 36 | + |
| 37 | +* When you save a Guardrail, you'll get an associated Guardrail ID - add this ID to the `before_request_hooks` or `after_request_hooks` params in your Portkey Config |
| 38 | +* Create these Configs in Portkey UI, save them, and get an associated Config ID to attach to your requests. [More here](/product/ai-gateway/configs). |
| 39 | + |
| 40 | +Here's an example configuration: |
| 41 | + |
| 42 | +```json |
| 43 | +{ |
| 44 | + "input_guardrails": ["guardrails-id-xxx"], |
| 45 | + "output_guardrails": ["guardrails-id-yyy"], |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +<Tabs> |
| 50 | + <Tab title="NodeJS"> |
| 51 | + |
| 52 | +```js |
| 53 | +const portkey = new Portkey({ |
| 54 | + apiKey: "PORTKEY_API_KEY", |
| 55 | + config: "pc-***" // Supports a string config id or a config object |
| 56 | +}); |
| 57 | +``` |
| 58 | + </Tab> |
| 59 | + <Tab title="Python"> |
| 60 | + |
| 61 | +```py |
| 62 | +portkey = Portkey( |
| 63 | + api_key="PORTKEY_API_KEY", |
| 64 | + config="pc-***" # Supports a string config id or a config object |
| 65 | +) |
| 66 | +``` |
| 67 | + </Tab> |
| 68 | + <Tab title="OpenAI NodeJS"> |
| 69 | + |
| 70 | +```js |
| 71 | +const openai = new OpenAI({ |
| 72 | + apiKey: 'OPENAI_API_KEY', |
| 73 | + baseURL: PORTKEY_GATEWAY_URL, |
| 74 | + defaultHeaders: createHeaders({ |
| 75 | + apiKey: "PORTKEY_API_KEY", |
| 76 | + config: "CONFIG_ID" |
| 77 | + }) |
| 78 | +}); |
| 79 | +``` |
| 80 | + </Tab> |
| 81 | + <Tab title="OpenAI Python"> |
| 82 | + |
| 83 | +```py |
| 84 | +client = OpenAI( |
| 85 | + api_key="OPENAI_API_KEY", # defaults to os.environ.get("OPENAI_API_KEY") |
| 86 | + base_url=PORTKEY_GATEWAY_URL, |
| 87 | + default_headers=createHeaders( |
| 88 | + provider="openai", |
| 89 | + api_key="PORTKEY_API_KEY", # defaults to os.environ.get("PORTKEY_API_KEY") |
| 90 | + config="CONFIG_ID" |
| 91 | + ) |
| 92 | +) |
| 93 | +``` |
| 94 | + </Tab> |
| 95 | +<Tab title="cURL"> |
| 96 | + |
| 97 | +```sh |
| 98 | +curl https://api.portkey.ai/v1/chat/completions \ |
| 99 | + -H "Content-Type: application/json" \ |
| 100 | + -H "Authorization: Bearer $OPENAI_API_KEY" \ |
| 101 | + -H "x-portkey-api-key: $PORTKEY_API_KEY" \ |
| 102 | + -H "x-portkey-config: $CONFIG_ID" \ |
| 103 | + -d '{ |
| 104 | + "model": "gpt-3.5-turbo", |
| 105 | + "messages": [{ |
| 106 | + "role": "user", |
| 107 | + "content": "Hello!" |
| 108 | + }] |
| 109 | + }' |
| 110 | +``` |
| 111 | + </Tab> |
| 112 | +</Tabs> |
| 113 | + |
| 114 | +For more, refer to the [Config documentation](/product/ai-gateway/configs). |
| 115 | + |
| 116 | +Your requests are now guarded by Prompt Security's protection mechanisms, and you can see the verdict and any actions taken directly in your Portkey logs! |
| 117 | + |
| 118 | +## Get Support |
| 119 | + |
| 120 | +If you face any issues with the Prompt Security integration, join the [Portkey community forum](https://discord.gg/portkey-llms-in-prod-1143393887742861333) for assistance. |
0 commit comments