PII 마스킹 v2
PII 마스킹 v2 (PII Masking v2, Presidio 기반)
LiteLLM의 PII 마스킹 가드레일은 Microsoft Presidio를 사용해 LLM 입력과 출력에서 개인 식별 정보(PII)를 자동 감지하고 마스킹해요. 사전 구축 감지기(PII, 이메일, SSN 등)와 커스텀 감지기를 모두 지원하며, 감지된 값을 임의 값으로 대체할 수 있어요.
출처: 문서
본문
개요 (Overview)
- 공급자: Presidio (
presidio_v2) - 지원 동작: MASK (감지된 PII를 대체 텍스트로 교체)
- 지원 모드: pre_call (입력), during_call, post_call (출력)
- 감지기 (detectors): presidio, email, ssn, name, credit_card, ip_address, phone_number 등 + 커스텀 감지기
- API 요구사항: 없음 (인프로세스로 실행)
프롬프트 인젝션과 같은 위험을 감지·차단하는 게 아니라, 요청/응답에서 PII를 찾아 마스킹된 형태로 교체해 민감 정보가 LLM 제공자에 도달하거나 최종 사용자에게 노출되는 것을 막는 데 초점을 둬요.
빠른 시작 (Quick Start)
1. LiteLLM config.yaml에 가드레일 정의하기
guardrails 섹션 아래에 가드레일을 정의하세요:
model_list:
- model_name: gpt-5.6-luna
litellm_params:
model: openai/gpt-5.6-luna
api_key: os.environ/OPENAI_API_KEY
guardrails:
- guardrail_name: "pii-mask"
litellm_params:
guardrail: presidio_v2
mode: "pre_call" # "post_call" or "pre_call,post_call" also supported
default_on: true
# Transform detected PII values
transform: # 📋 Required
- type: "mask" # or "replace"
replace: "[PII]"
# Enable + configure detectors
detectors:
- type: "pii"
enabled: true
- type: "email"
enabled: true
- type: "ssn"
enabled: true
- type: "name"
enabled: true
- type: "credit_card"
enabled: true
- type: "ip_address"
enabled: true
- type: "phone_number"
enabled: true
mode에 대한 지원 값 (Supported values for mode):
pre_call- LLM 호출 전, 입력 메시지에서 PII 마스킹during_call- LLM 호출과 병행post_call- LLM 호출 후, 출력 응답에서 PII 마스킹pre_call,post_call- 입력과 출력 모두 마스킹
2. LiteLLM 게이트웨이 시작
litellm --config config.yaml --detailed_debug
3. 테스트 요청
입력 마스킹 (pre_call):
curl -i http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-luna",
"messages": [
{"role": "user", "content": "My email is [email protected] and my SSN is 234-56-7890"}
],
"guardrails": ["pii-mask"]
}'
요청이 LLM에 보내질 때 이메일과 SSN이 마스킹되어 보내져요:
My email is [PII] and my SSN is [PII]
지원되는 감지기 (Supported detectors)
| 감지기 | 감지 내용 |
|---|---|
| presidio | Presidio 기본 분석기로 감지된 PII (기본 다수 유형) |
| 이메일 주소 | |
| ssn | 사회보장번호 |
| name | 사람 이름 |
| credit_card | 신용카드 번호 |
| ip_address | IP 주소 |
| phone_number | 전화번호 |
| custom | 사용자 정의 감지기 패턴 |
transform 옵션 (Transform options)
type: "mask"- 감지된 값을 고정된replace텍스트로 교체type: "replace"- 감지된 값을 지정된 값으로 교체
보안 참고 (Security notes)
이 가드레일은 인프로세스에서 실행되므로 외부 API 호출이 없어 민감 데이터가 프록시 밖으로 나가지 않아요. 마스킹된 요청/응답은 LLM 제공자로, 그리고 최종 사용자에게 안전하게 전달돼요.
참고 사항 (Notes)
커스텀 감지기 정의, 여러 가드레일 조합, 키/프로젝트별 가드레일 제어에 대한 자세한 내용은 원문 문서를 참고하세요. 원문 문서는 이 v2 버전에서 각 감지기의 세부 파라미터(예: 특정 PII 유형별 구성)와 함께 더 많은 예시를 제공해요.