호출 후 규칙
호출 후 규칙 (Post-Call Rules)
LLM API 호출의 출력을 기준으로 요청을 실패시키는 데 사용해요.
출처: 문서
본문
빠른 시작 (Quick Start)
1단계: 파일 만들기 (예: post_call_rules.py)
def my_custom_rule(input): # receives the model response
if len(input) < 5:
return {
"decision": False,
"message": "This violates LiteLLM Proxy Rules. Response too short"
}
return {"decision": True} # message not required since, request will pass
2단계: 프록시에 연결하기
litellm_settings:
post_call_rules: post_call_rules.my_custom_rule
3단계: 프록시 시작 및 테스트
$ litellm /path/to/config.yaml
curl --location 'http://0.0.0.0:4000/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ***" \
--data '{
"model": "gpt-5.6-luna",
"messages": [{"role":"user","content":"What llm are you?"}],
"temperature": 0.7,
"max_tokens": 10,
}'
이제 응답 길이가 5보다 큰지 검사해요. 조건을 지키지 못하면 3번 재시도한 뒤 실패 처리돼요.
규칙을 위반한 응답
규칙 위반 시 LiteLLM Proxy가 반환하는 응답이에요.
{
"error":
{
"message":"This violates LiteLLM Proxy Rules. Response too short",
"type":null,
"param":null,
"code":500
}
}