Skip to content

Commit c471bf1

Browse files
authored
feat(guardrails): Add content masking and streaming support to PANW Prisma AIRS guardrail (#15666)
* feat(guardrails): Add content masking and streaming support to PANW Prisma AIRS - Add mask_request_content and mask_response_content parameters - Implement content masking for prompts and responses - Add streaming support with real-time masking - Add comprehensive test coverage (28 tests) - Update documentation with masking examples and security notes * fix(guardrails): Fix PANW Prisma AIRS env var fallback and text completion support
1 parent 645f84c commit c471bf1

File tree

5 files changed

+1187
-138
lines changed

5 files changed

+1187
-138
lines changed

docs/my-website/docs/proxy/guardrails/panw_prisma_airs.md

Lines changed: 124 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ LiteLLM supports PANW Prisma AIRS (AI Runtime Security) guardrails via the [Pris
1111
-**Real-time prompt injection detection**
1212
-**Malicious content filtering**
1313
-**Data loss prevention (DLP)**
14+
-**Sensitive content masking** - Automatically mask PII, credit cards, SSNs instead of blocking
1415
-**Comprehensive threat detection** for AI models and datasets
1516
-**Model-agnostic protection** across public and private models
1617
-**Synchronous scanning** with immediate response
1718
-**Configurable security profiles**
19+
-**Streaming support** - Real-time masking for streaming responses
20+
-**Fail-closed security** - Blocks requests if PANW API is unavailable (maximum security)
1821

1922
## Quick Start
2023

@@ -42,9 +45,9 @@ guardrails:
4245
litellm_params:
4346
guardrail: panw_prisma_airs
4447
mode: "pre_call" # Run before LLM call
45-
api_key: os.environ/AIRS_API_KEY # Your PANW API key
46-
profile_name: os.environ/AIRS_API_PROFILE_NAME # Security profile from Strata Cloud Manager
47-
api_base: "https://service.api.aisecurity.paloaltonetworks.com/v1/scan/sync/request" # Optional
48+
api_key: os.environ/PANW_PRISMA_AIRS_API_KEY # Your Prisma AIRS API key
49+
profile_name: os.environ/PANW_PRISMA_AIRS_PROFILE_NAME # Security profile from Strata Cloud Manager
50+
api_base: "https://service.api.aisecurity.paloaltonetworks.com"
4851
```
4952
5053
#### Supported values for `mode`
@@ -56,8 +59,8 @@ guardrails:
5659
### 3. Start LiteLLM Gateway
5760

5861
```bash title="Set environment variables"
59-
export AIRS_API_KEY="your-panw-api-key"
60-
export AIRS_API_PROFILE_NAME="your-security-profile"
62+
export PANW_PRISMA_AIRS_API_KEY="your-panw-api-key"
63+
export PANW_PRISMA_AIRS_PROFILE_NAME="your-security-profile"
6164
export OPENAI_API_KEY="sk-proj-..."
6265
```
6366

@@ -197,16 +200,16 @@ Expected successful response:
197200
|-----------|----------|-------------|---------|
198201
| `api_key` | Yes | Your PANW Prisma AIRS API key from Strata Cloud Manager | - |
199202
| `profile_name` | Yes | Security profile name configured in Strata Cloud Manager | - |
200-
| `api_base` | No | Custom API endpoint | `https://service.api.aisecurity.paloaltonetworks.com/v1/scan/sync/request` |
203+
| `api_base` | No | Custom API base URL (without /v1/scan/sync/request path) | `https://service.api.aisecurity.paloaltonetworks.com` |
201204
| `mode` | No | When to run the guardrail | `pre_call` |
202205

203206
## Environment Variables
204207

205208
```bash
206-
export AIRS_API_KEY="your-panw-api-key"
207-
export AIRS_API_PROFILE_NAME="your-security-profile"
208-
# Optional custom endpoint
209-
export PANW_API_ENDPOINT="https://custom-endpoint.com/v1/scan/sync/request"
209+
export PANW_PRISMA_AIRS_API_KEY="your-panw-api-key"
210+
export PANW_PRISMA_AIRS_PROFILE_NAME="your-security-profile"
211+
# Optional custom base URL (without /v1/scan/sync/request path)
212+
export PANW_PRISMA_AIRS_API_BASE="https://custom-endpoint.com/"
210213
```
211214

212215
## Advanced Configuration
@@ -221,17 +224,125 @@ guardrails:
221224
litellm_params:
222225
guardrail: panw_prisma_airs
223226
mode: "pre_call"
224-
api_key: os.environ/AIRS_API_KEY
227+
api_key: os.environ/PANW_PRISMA_AIRS_API_KEY
225228
profile_name: "strict-policy" # High security profile
226229
227230
- guardrail_name: "panw-permissive-security"
228231
litellm_params:
229232
guardrail: panw_prisma_airs
230233
mode: "post_call"
231-
api_key: os.environ/AIRS_API_KEY
234+
api_key: os.environ/PANW_PRISMA_AIRS_API_KEY
232235
profile_name: "permissive-policy" # Lower security profile
233236
```
234237

238+
### Content Masking
239+
240+
PANW Prisma AIRS can automatically mask sensitive content (PII, credit cards, SSNs, etc.) instead of blocking requests. This allows your application to continue functioning while protecting sensitive data.
241+
242+
#### How It Works
243+
244+
1. **Detection**: PANW scans content and identifies sensitive data
245+
2. **Masking**: Sensitive data is replaced with placeholders (e.g., `XXXXXXXXXX` or `{PHONE}`)
246+
3. **Pass-through**: Masked content is sent to the LLM or returned to the user
247+
248+
#### Configuration Options
249+
250+
```yaml
251+
guardrails:
252+
- guardrail_name: "panw-with-masking"
253+
litellm_params:
254+
guardrail: panw_prisma_airs
255+
mode: "post_call" # Scan both input and output
256+
api_key: os.environ/PANW_PRISMA_AIRS_API_KEY
257+
profile_name: "default"
258+
mask_request_content: true # Mask sensitive data in prompts
259+
mask_response_content: true # Mask sensitive data in responses
260+
```
261+
262+
**Masking Parameters:**
263+
264+
- `mask_request_content: true` - When PANW detects sensitive data in prompts, mask it instead of blocking
265+
- `mask_response_content: true` - When PANW detects sensitive data in responses, mask it instead of blocking
266+
- `mask_on_block: true` - Backwards compatible flag that enables both request and response masking
267+
268+
:::warning Important: Masking is Controlled by PANW Security Profile
269+
The **actual masking behavior** (what content gets masked and how) is controlled by your **PANW Prisma AIRS security profile** configured in Strata Cloud Manager. The LiteLLM config settings (`mask_request_content`, `mask_response_content`) only control whether to:
270+
- **Apply the masked content** returned by PANW and allow the request to continue, OR
271+
- **Block the request** entirely when sensitive data is detected
272+
273+
LiteLLM does not alter or configure your PANW security profile. To change what content gets masked, update your profile settings in Strata Cloud Manager.
274+
:::
275+
276+
:::info Security Posture
277+
The guardrail is **fail-closed** by default - if the PANW API is unavailable, requests are blocked to ensure no unscanned content reaches your LLM. This provides maximum security.
278+
:::
279+
280+
#### Example: Masking Credit Card Numbers
281+
282+
<Tabs>
283+
<TabItem label="Without Masking" value="no-mask">
284+
285+
**Request:**
286+
```json
287+
{
288+
"messages": [
289+
{"role": "user", "content": "My credit card is 4929-3813-3266-4295"}
290+
]
291+
}
292+
```
293+
294+
**Response:** ❌ **Blocked with 400 error**
295+
296+
</TabItem>
297+
<TabItem label="With Masking" value="with-mask">
298+
299+
**Request:**
300+
```json
301+
{
302+
"messages": [
303+
{"role": "user", "content": "My credit card is 4929-3813-3266-4295"}
304+
]
305+
}
306+
```
307+
308+
**Masked prompt sent to LLM:**
309+
```json
310+
{
311+
"messages": [
312+
{"role": "user", "content": "My credit card is XXXXXXXXXXXXXXXXXX"}
313+
]
314+
}
315+
```
316+
317+
**Response:** ✅ **Allowed with masked content**
318+
319+
</TabItem>
320+
</Tabs>
321+
322+
#### Masking Capabilities
323+
324+
The guardrail masks sensitive content in:
325+
326+
- ✅ **Chat messages** - User prompts and assistant responses
327+
- ✅ **Streaming responses** - Real-time masking of streamed content
328+
- ✅ **Multi-choice responses** - All choices in the response
329+
- ✅ **Tool/function calls** - Arguments passed to tools and functions
330+
- ✅ **Content lists** - Mixed content types (text, images, etc.)
331+
332+
#### Complete Example
333+
334+
```yaml
335+
guardrails:
336+
- guardrail_name: "panw-production-security"
337+
litellm_params:
338+
guardrail: panw_prisma_airs
339+
mode: "post_call" # Scan input and output
340+
api_key: os.environ/PANW_PRISMA_AIRS_API_KEY
341+
profile_name: "production-profile"
342+
mask_request_content: true # Mask sensitive prompts
343+
mask_response_content: true # Mask sensitive responses
344+
```
345+
235346
## Use Cases
236347

237348
From [official Prisma AIRS documentation](https://docs.paloaltonetworks.com/ai-runtime-security/activation-and-onboarding/ai-runtime-security-api-intercept-overview):
@@ -245,7 +356,7 @@ From [official Prisma AIRS documentation](https://docs.paloaltonetworks.com/ai-r
245356
## Next Steps
246357

247358
- Configure your security policies in [Strata Cloud Manager](https://apps.paloaltonetworks.com/)
248-
- Review the [Prisma AIRS API documentation](https://pan.dev/prisma-airs/api/airuntimesecurity/scan-sync-request/) for advanced features
359+
- Review the [Prisma AIRS API documentation](https://pan.dev/airs/) for advanced features
249360
- Set up monitoring and alerting for threat detections in your PANW dashboard
250361
- Consider implementing both pre_call and post_call guardrails for comprehensive protection
251362
- Monitor detection events and tune your security profiles based on your application needs

litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail"
1313

1414
guardrail_name = guardrail.get("guardrail_name")
1515
profile_name = cast(Optional[str], getattr(litellm_params, "profile_name", None))
16-
if not litellm_params.api_key:
17-
raise ValueError("PANW Prisma AIRS: api_key is required")
16+
17+
# Note: api_key can be None here - handler will fallback to PANW_PRISMA_AIRS_API_KEY env var
1818
if not profile_name:
1919
raise ValueError("PANW Prisma AIRS: profile_name is required")
2020
if not guardrail_name:

0 commit comments

Comments
 (0)