fix: wrap non-JSON decisions responses in DecisionsResponseValidationError

transform_decisions_response validated the raw body with validate_json outside
the try/except, so a non-JSON upstream body (e.g. an HTML error page) raised an
unhandled pydantic ValidationError. Move validate_json inside the try so a
malformed body surfaces as DecisionsResponseValidationError, like a schema
mismatch in parse_response.

Fixes #48660
This commit is contained in:
Ahmet Selim FEDAKAR 2026-10-28 13:18:16 +03:00
parent cfe0100e1f
commit 95b22abd0f
2 changed files with 27 additions and 1 deletions

View file

@ -657,8 +657,8 @@ class BaseDecisionsConfig(ABC):
raw_response: httpx.Response,
request: DecisionsIRRequest,
) -> DecisionsIRResponse:
payload: Final[object] = _PAYLOAD_ADAPTER.validate_json(raw_response.content)
try:
payload: Final[object] = _PAYLOAD_ADAPTER.validate_json(raw_response.content)
return self.parse_response(payload, request)
except ValidationError as error:
raise DecisionsResponseValidationError(

View file

@ -0,0 +1,26 @@
from typing import cast
import httpx
import pytest
from litellm.llms.base_llm.decisions.transformation import (
BaseDecisionsConfig,
DecisionsResponseValidationError,
)
from litellm.types.decisions import DecisionsIRRequest
def test_transform_decisions_response_wraps_non_json_body():
"""Regression for #48660: a non-JSON response body raised an unhandled
pydantic ValidationError because `validate_json` ran outside the
try/except. It must surface as DecisionsResponseValidationError instead."""
config = BaseDecisionsConfig()
raw_response = httpx.Response(status_code=502, content=b"<html>Bad Gateway</html>")
with pytest.raises(DecisionsResponseValidationError):
config.transform_decisions_response(
model="jev-latest",
custom_llm_provider="systemone",
raw_response=raw_response,
request=cast(DecisionsIRRequest, None),
)