From 0691ff8d136b445eb316be2f7b134d1bafa70c8a Mon Sep 17 00:00:00 2001 From: "Jugal D. Bhatt" <55304795+jugaldb@users.noreply.github.com> Date: Fri, 11 Jul 2025 04:24:48 +0530 Subject: [PATCH] Added validate payload error (#12494) * Added validate payload error * added logger * added test case --- .../proxy/common_utils/http_parsing_utils.py | 24 +++-- .../common_utils/test_http_parsing_utils.py | 87 +++++++++++++++++++ 2 files changed, 105 insertions(+), 6 deletions(-) diff --git a/litellm/proxy/common_utils/http_parsing_utils.py b/litellm/proxy/common_utils/http_parsing_utils.py index 6ded2f000c..875d69437c 100644 --- a/litellm/proxy/common_utils/http_parsing_utils.py +++ b/litellm/proxy/common_utils/http_parsing_utils.py @@ -5,6 +5,7 @@ import orjson from fastapi import Request, UploadFile, status from litellm._logging import verbose_proxy_logger +from litellm.proxy._types import ProxyException from litellm.types.router import Deployment @@ -44,8 +45,8 @@ async def _read_request_body(request: Optional[Request]) -> Dict: else: try: parsed_body = orjson.loads(body) - except orjson.JSONDecodeError: - # Fall back to the standard json module which is more forgiving + except orjson.JSONDecodeError as e: + # First try the standard json module which is more forgiving # First decode bytes to string if needed body_str = body.decode("utf-8") if isinstance(body, bytes) else body @@ -61,15 +62,26 @@ async def _read_request_body(request: Optional[Request]) -> Dict: r"(?