가드레일 공급자: Aporia

가드레일 공급자: Aporia

Aporia를 사용해 요청의 PII와 응답의 욕설을 감지해요.

출처: 문서

본문

1. Aporia에서 가드레일 설정하기

Aporia 프로젝트 생성

Aporia에 두 개의 프로젝트를 만드세요:

  • Pre LLM API Call - pre LLM API 호출에서 실행할 모든 정책 설정
  • Post LLM API Call - post LLM API 호출에서 실행할 모든 정책 설정

Pre-Call: PII 감지 — PII - Prompt를 Pre LLM API Call 프로젝트에 추가.

Post-Call: 응답의 욕설 감지 — Toxicity - Response를 Post LLM API Call 프로젝트에 추가.

2. 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: "aporia-pre-guard"
    litellm_params:
      guardrail: aporia  # supported values: "aporia", "lakera"
      mode: "during_call"
      api_key: os.environ/APORIA_API_KEY_1
      api_base: os.environ/APORIA_API_BASE_1
  - guardrail_name: "aporia-post-guard"
    litellm_params:
      guardrail: aporia  # supported values: "aporia", "lakera"
      mode: "post_call"
      api_key: os.environ/APORIA_API_KEY_2
      api_base: os.environ/APORIA_API_BASE_2

mode에 대한 지원 값 (Supported values for mode):

  • pre_call LLM 호출 전, 입력에 대해 실행
  • post_call LLM 호출 후, 입력 & 출력에 대해 실행
  • during_call LLM 호출 중, 입력에 대해 실행. pre_call과 같지만 LLM 호출과 병행 실행. 가드레일 검사가 완료될 때까지 응답이 반환되지 않음

3. LiteLLM 게이트웨이 시작

litellm --config config.yaml --detailed_debug

4. 테스트 요청

실패 호출

[email protected]가 요청에 있는 PII이므로 실패할 것으로 예상하세요:

curl -i http://localhost:4000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ***" \
  -d '{
    "model": "gpt-5.6-luna",
    "messages": [
      {"role": "user", "content": "hi my email is [email protected]"}
    ],
    "guardrails": ["aporia-pre-guard", "aporia-post-guard"]
  }'

실패 시 예상 응답:

{
  "error": {
    "message": {
      "error": "Violated guardrail policy",
      "aporia_ai_response": {
        "action": "block",
        "revised_prompt": null,
        "revised_response": "Aporia detected and blocked PII",
        "explain_log": null
      }
    },
    "type": "None",
    "param": "None",
    "code": "400"
  }
}

성공 호출

curl -i http://localhost:4000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ***" \
  -d '{
    "model": "gpt-5.6-luna",
    "messages": [
      {"role": "user", "content": "hi what is the weather"}
    ],
    "guardrails": ["aporia-pre-guard", "aporia-post-guard"]
  }'

5. ✨ 프로젝트(API 키)별 가드레일 제어 (Control Guardrails per Project)

Enterprise 기능

이 기능은 LiteLLM Enterprise 라이선스가 필요해요. 무료 30일 체험판을 시작하거나 데모를 예약하세요. Enterprise에 포함된 것 보기.

이 기능으로 프로젝트별 실행할 가드레일을 제어해요. 이 튜토리얼에서는 1개의 프로젝트(API Key)에 대해 다음 가드레일만 실행되길 원해요:

guardrails: ["aporia-pre-guard", "aporia-post-guard"]

1단계: 가드레일 설정으로 키 만들기

/key/generate:

curl -X POST 'http://0.0.0.0:4000/key/generate' \
    -H "Authorization: Bearer ***" \
    -H 'Content-Type: application/json' \
    -d '{
            "guardrails": ["aporia-pre-guard", "aporia-post-guard"]
        }
    }'

/key/update:

curl --location 'http://0.0.0.0:4000/key/update' \
    --header "Authorization: Bearer ***" \
    --header 'Content-Type: application/json' \
    --data '{
        "key": "«redacted:sk-…»",
        "guardrails": ["aporia-pre-guard", "aporia-post-guard"]
        }
}'

2단계: 새 키로 테스트

curl --location 'http://0.0.0.0:4000/chat/completions' \
    --header 'Authorization: Bearer ***' \
    --header 'Content-Type: application/json' \
    --data '{
    "model": "gpt-5.6-luna",
    "messages": [
        {
        "role": "user",
        "content": "my email is [email protected]"
        }
    ]
}'