가드레일 공급자: Guardrails AI
가드레일 공급자: Guardrails AI
Guardrails AI (guardrailsai.com)를 사용해 LLM 출력에 검사를 추가해요.
출처: 문서
본문
사전 요구사항 (Pre-requisites)
Guardrails AI Server를 설정하세요. quick start.
사용법 (Usage)
config.yaml 설정:
model_list:
- model_name: gpt-5.6-luna
litellm_params:
model: gpt-5.6-luna
api_key: os.environ/OPENAI_API_KEY
guardrails:
- guardrail_name: "guardrails_ai-guard"
litellm_params:
guardrail: guardrails_ai
guard_name: "detect-secrets-guard" # 👈 Guardrail AI guard name
mode: "pre_call"
guardrails_ai_api_input_format: "llmOutput" # 👈 This is the only option that currently works (and it is a default), use it for both pre_call and post_call hooks
api_base: os.environ/GUARDRAILS_AI_API_BASE # 👈 Guardrails AI API Base. Defaults to "http://0.0.0.0:8000"
LiteLLM 게이트웨이 시작:
litellm --config config.yaml --detailed_debug
테스트 요청:
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": ["guardrails_ai-guard"]
}'
✨ 프로젝트(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": ["guardrails_ai-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": ["guardrails_ai-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]"
}
]
}'