mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-17 09:34:48 +00:00
fix(dashscope): classify data inspection errors
This commit is contained in:
parent
bc9f4fec5b
commit
78e66e2a8b
2 changed files with 24 additions and 0 deletions
|
|
@ -335,6 +335,7 @@ def _map_openai_exception(
|
|||
("invalid_request_error" in error_str and "content_policy_violation" in error_str)
|
||||
or ("Invalid prompt" in error_str and "violating our usage policy" in error_str)
|
||||
or ("request was rejected as a result of the safety system" in error_str.lower())
|
||||
or (custom_llm_provider == "dashscope" and "datainspectionfailed" in error_str.lower())
|
||||
):
|
||||
raise ContentPolicyViolationError(
|
||||
message=f"ContentPolicyViolationError: {exception_provider} - {message}",
|
||||
|
|
|
|||
|
|
@ -342,6 +342,29 @@ def test_openai_compatible_400_with_bare_429_in_body_maps_to_bad_request():
|
|||
assert excinfo.value.llm_provider == "deepinfra"
|
||||
|
||||
|
||||
def test_dashscope_data_inspection_failure_maps_to_content_policy_violation():
|
||||
error_message = (
|
||||
'{"error":{"message":"InternalError.Algo.DataInspectionFailed: '
|
||||
'Input text data may contain inappropriate content.",'
|
||||
'"type":"invalid_request_error","code":"invalid_request_error"}}'
|
||||
)
|
||||
original_exception = OpenAIError(
|
||||
status_code=400,
|
||||
message=error_message,
|
||||
headers={},
|
||||
)
|
||||
|
||||
with pytest.raises(litellm.ContentPolicyViolationError) as excinfo:
|
||||
exception_type(
|
||||
model="dashscope/qwen-plus",
|
||||
original_exception=original_exception,
|
||||
custom_llm_provider="dashscope",
|
||||
)
|
||||
|
||||
assert excinfo.value.status_code == 400
|
||||
assert excinfo.value.llm_provider == "dashscope"
|
||||
|
||||
|
||||
def test_openai_compatible_429_still_maps_to_rate_limit():
|
||||
"""A real 429 still maps to RateLimitError."""
|
||||
original_exception = OpenAIError(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue