✨ 비밀 감지/검열
✨ 비밀 감지/검열 (Secret Detection/Redaction, Enterprise 전용)
LLM으로 보내는 요청 안의 API 키, 비밀(secrets)을 REDACT(검열) 처리할 때 사용해요. 예를 들어 아래 요청에서 OPENAI_API_KEY의 값을 검열하고 싶다면요.
출처: 문서
본문
들어오는 요청 (Incoming Request)
{
"messages": [
{
"role": "user",
"content": "Hey, how's it going, API_KEY = 'sk_123...cdef'"
}
]
}
모더레이션 후 요청 (Request after Moderation)
{
"messages": [
{
"role": "user",
"content": "Hey, how's it going, API_KEY = '[REDACTED]'"
}
]
}
사용법 (Usage)
1단계. config.yaml에 추가하기.
guardrails:
- guardrail_name: "my-custom-name"
litellm_params:
guardrail: "hide-secrets" # supported values: "aporia", "lakera", ..
mode: "pre_call"
2단계. 서버 로그를 보려면 --detailed_debug로 litellm 프록시를 실행하기.
litellm --config config.yaml --detailed_debug
3단계. 요청으로 테스트하기.
curl -L -X POST 'http://0.0.0.0:4000/v1/chat/completions' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ***" \
-d '{
"model": "fake-claude-endpoint",
"messages": [
{
"role": "user",
"content": "what is the value of my open ai key? openai_api_key=***"
}
],
"guardrails": ["my-custom-name"]
}'
litellm 서버 로그에 다음 경고가 표시될 것으로 예상해요.
LiteLLM Proxy:WARNING: secret_detection.py:88 - Detected and redacted secrets in message: ['Secret Keyword']
--detailed_debug로 litellm이 API 프로바이더에 보낸 원본 요청도 볼 수 있어요.
POST Request Sent from LiteLLM:
curl -X POST \
https://api.groq.com/openai/v1/ \
-H 'Authorization: Bearer gsk_my...****' \
-d {
"model": "llama3-8b-8192",
"messages": [
{
"role": "user",
"content": "what is the time today, openai_api_key=[REDACTED]"
}
],
"stream": false,
"extra_body": {}
}
프로젝트별(API KEY/팀) 켜고 끄기
여기를 참고하세요.
비밀 감지기 제어하기 (Control secret detectors)
LiteLLM은 비밀 감지에 detect-secrets 라이브러리를 사용해요. 기본으로 실행되는 모든 플러그인을 확인하세요.
사용법
요청별로 어떤 플러그인을 실행할지 제어하는 방법이에요. 비밀 감지가 응답 품질에 영향을 준다고 개발자가 불만을 제기할 때 유용해요.
- config.yaml 설정하기.
guardrails:
- guardrail_name: "hide-secrets"
litellm_params:
guardrail: "hide-secrets" # supported values: "aporia", "lakera"
mode: "pre_call"
detect_secrets_config: {
"plugins_used": [
{"name": "SoftlayerDetector"},
{"name": "StripeDetector"},
{"name": "NpmDetector"}
]
}
- 프록시 시작하기. 더 자세한 로그를 보려면
--detailed_debug로 실행해요. 개발용으로만 사용하세요.
litellm --config /path/to/config.yaml --detailed_debug
- 테스트하기!
curl -L -X POST 'http://0.0.0.0:4000/v1/chat/completions' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ***" \
-d '{
"model": "fake-claude-endpoint",
"messages": [
{
"role": "user",
"content": "what is the value of my open ai key? openai_api_key=***"
}
],
"guardrails": ["hide-secrets"]
}'
예상 로그. 변경 사항이 의도대로 적용됐는지 확인하려면 로그에서 이것을 찾아보세요.
No secrets detected on input.
사용되는 기본 설정 (Default Config Used)
LiteLLM은 detect-secrets 라이브러리의 전체 플러그인 세트를 기본으로 실행하며, 다음은 그 기본 설정의 앞부분이에요.
_default_detect_secrets_config = {
"plugins_used": [
{"name": "SoftlayerDetector"},
{"name": "StripeDetector"},
{"name": "NpmDetector"},
{"name": "IbmCosHmacDetector"},
{"name": "DiscordBotTokenDetector"},
{"name": "BasicAuthDetector"},
{"name": "AzureStorageKeyDetector"},
{"name": "ArtifactoryDetector"},
{"name": "AWSKeyDetector"},
{"name": "CloudantDetector"},
{"name": "IbmCloudIamDetector"},
{"name": "JwtTokenDetector"},
{"name": "MailchimpDetector"},
{"name": "SquareOAuthDetector"},
{"name": "PrivateKeyDetector"},
{"name": "TwilioKeyDetector"},
# ... 이어서 AdafruitKeyDetector, AdobeSecretDetector, AgeSecretKeyDetector,
# AirtableApiKeyDetector, AlgoliaApiKeyDetector, AlibabaSecretDetector,
# AsanaSecretDetector, AtlassianApiTokenDetector, AuthressAccessKeyDetector,
# BittrexDetector 등 detect-secrets의 전체 커스텀 플러그인 세트가 계속됨
]
}
기본 감지기는 Softlayer, Stripe, Npm, IbmCosHmac, DiscordBotToken, BasicAuth, AzureStorageKey, Artifactory, AWSKey, Cloudant, IbmCloudIam, JwtToken, Mailchimp, SquareOAuth, PrivateKey, TwilioKey 등과 함께 Adafruit, Adobe, Age, Airtable, Algolia, Alibaba, Asana, Atlassian, Authress, Bittrex 등 수십 개의 커스텀 플러그인으로 구성돼요. 전체 목록과 각 플러그인의 경로는 detect-secrets 라이브러리 설정에서 확인할 수 있어요.