跳至主要內容

Pillar Security

Pillar Security 透過 Generic Guardrail APILiteLLM Proxy 整合,為您的 LLM 應用程式提供完整的 AI 安全掃描。

  • Prompt Injection Protection:防止惡意 prompt 操作
  • Jailbreak Detection:偵測繞過 AI 安全措施的嘗試
  • PII + PCI Detection:自動偵測敏感個人資料與支付卡資訊
  • Secret Detection:識別 API 金鑰、token 與憑證
  • Content Moderation:篩選有害或不當內容
  • Toxic Language:篩選攻擊性或有害語言

快速開始

1. 設定環境變數

export PILLAR_API_KEY=your-pillar-api-key
export OPENAI_API_KEY=your-openai-api-key

2. 設定 LiteLLM

建立或更新您的 config.yaml

model_list:
- model_name: gpt-4o
litellm_params:
model: openai/gpt-4o
api_key: os.environ/OPENAI_API_KEY

guardrails:
- guardrail_name: pillar-security
litellm_params:
guardrail: generic_guardrail_api
mode: [pre_call, post_call]
api_base: https://api.pillar.security/api/v1/integrations/litellm
api_key: os.environ/PILLAR_API_KEY
default_on: true
additional_provider_specific_params:
plr_mask: true
plr_evidence: true
plr_scanners: true
Important
  • api_base 必須完全等於 https://api.pillar.security/api/v1/integrations/litellm — 這是唯一支援 Generic Guardrail API 整合的端點。
  • guardrail: generic_guardrail_api 的值不可更改。這是 LiteLLM 內建的 guardrail 類型。不過,您可以將 guardrail_name 自訂為任何您偏好的值。

3. 啟動 LiteLLM Proxy

litellm --config config.yaml --port 4000

4. 測試整合

curl -X POST "http://localhost:4000/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-master-key" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello, how are you?"}]
}'

必要條件

在開始之前,請確認您已具備:

  1. Pillar Security 帳戶:在 Pillar Dashboard 註冊
  2. API 憑證:從儀表板取得您的 API 金鑰
  3. LiteLLM Proxy:安裝並設定 LiteLLM proxy

Guardrail 模式

Pillar Security 支援三種執行模式,以提供完整保護:

模式執行時間保護內容使用情境
pre_call在 LLM 呼叫之前僅使用者輸入封鎖惡意 prompts,防止 prompt injection
during_call與 LLM 呼叫並行僅使用者輸入低延遲的輸入監控
post_call在 LLM 回應之後完整對話內容輸出篩選、回應中的 PII/PCI 偵測
Recommended

使用 [pre_call, post_call] 以完整保護輸入與輸出。

  • 完整保護:同時保護傳入的 prompts 與傳出的回應
  • Prompt Injection 防禦:在惡意輸入到達 LLM 前加以封鎖
  • 回應監控:偵測輸出中的 PII、secret 或不當內容
  • 完整內容分析:Pillar 可查看完整對話以提升偵測效果

設定參考

核心參數

參數說明
guardrail必須是 generic_guardrail_api(請勿更改此值)
api_base必須是 https://api.pillar.security/api/v1/integrations/litellm(請勿更改此值)
api_keyPillar API 金鑰(以 x-api-key 標頭傳送)
mode執行時間:pre_callpost_callduring_call,或類似 [pre_call, post_call] 的陣列
default_on預設為所有請求啟用 guardrail

Pillar 專屬參數

這些參數透過 additional_provider_specific_params 傳入:

參數類型說明
plr_maskbool在將資料送往 LLM 前,自動遮罩敏感資料(PII、PCI、secret)
plr_evidencebool在回應中包含偵測證據
plr_scannersbool在回應中包含掃描器詳細資訊
plr_persistbool將 session 資料儲存到 Pillar 儀表板
提示

啟用 plr_mask: true,可在敏感資料(PII、secret、支付卡資訊)到達 LLM 前自動進行去識別化處理。被遮罩的內容會以替代字元取代,而原始資料會保留在 Pillar 的稽核記錄中。

設定範例

最適合:

  • 完整保護:同時保護傳入的 prompts 與傳出的回應
  • 最高可視性:完整的掃描器與證據細節,便於除錯
  • 正式環境使用:使用持久化 sessions 進行儀表板監控
model_list:
- model_name: gpt-4o
litellm_params:
model: openai/gpt-4o
api_key: os.environ/OPENAI_API_KEY

guardrails:
- guardrail_name: pillar-security
litellm_params:
guardrail: generic_guardrail_api
mode: [pre_call, post_call]
api_base: https://api.pillar.security/api/v1/integrations/litellm
api_key: os.environ/PILLAR_API_KEY
default_on: true
additional_provider_specific_params:
plr_mask: true
plr_evidence: true
plr_scanners: true
plr_persist: true

general_settings:
master_key: "your-secure-master-key-here"

litellm_settings:
set_verbose: true

回應詳細程度

使用 plr_scannersplr_evidence 控制回應中包含哪些偵測資料:

最小回應

plr_scannersplr_evidence 皆為 false 時:

{
"session_id": "abc-123",
"flagged": true
}

當您只在意 Pillar 是否偵測到威脅時使用。

掃描器分解

plr_scanners: true 時:

{
"session_id": "abc-123",
"flagged": true,
"scanners": {
"jailbreak": true,
"prompt_injection": false,
"pii": false,
"secret": false,
"toxic_language": false
}
}

當您需要知道是哪一些類別觸發時使用。

完整內容

plr_scanners: trueplr_evidence: true 皆為真時:

{
"session_id": "abc-123",
"flagged": true,
"scanners": {
"jailbreak": true
},
"evidence": [
{
"category": "jailbreak",
"type": "prompt_injection",
"evidence": "Ignore previous instructions",
"metadata": { "start_idx": 0, "end_idx": 28 }
}
]
}

適合用於除錯、稽核記錄或合規匯出。

提示

務必設定 plr_scanners: trueplr_evidence: true,以查看 Pillar 偵測到的內容。這對於疑難排解與理解安全威脅至關重要。

Session 追蹤

Pillar 使用 LiteLLM 的 metadata 系統支援完整的 session 追蹤:

curl -X POST "http://localhost:4000/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-key" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello!"}],
"user": "user-123",
"metadata": {
"pillar_session_id": "conversation-456"
}
}'

這提供清楚且明確的對話追蹤,並可與 LiteLLM 的 session 管理無縫搭配。

環境變數

將您的 Pillar API 金鑰設為環境變數:

export PILLAR_API_KEY=your-pillar-api-key

範例

安全請求

curl -X POST "http://localhost:4000/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-master-key-here" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello! Can you tell me a joke?"}],
"max_tokens": 100
}'

預期回應(允許):

{
"id": "chatcmpl-BvQhm0VZpiDSEbrssSzO7GLHgHCkW",
"object": "chat.completion",
"created": 1753027050,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": "Sure! Here's a joke for you:\n\nWhy don't scientists trust atoms?\nBecause they make up everything!"
}
}
]
}

下一步

  • 監控您的應用程式:使用 Pillar Dashboard 查看安全事件與分析
  • 自訂偵測:針對您的使用情境設定特定的掃描器與閾值
  • 擴展您的部署:將 LiteLLM 的負載平衡功能與 Pillar 保護搭配使用

支援

您的 LiteLLM 整合需要協助嗎?請聯絡 support@pillar.security

資源