diff --git a/agents-api/agents_api/web.py b/agents-api/agents_api/web.py index 1c774691..15554a81 100644 --- a/agents-api/agents_api/web.py +++ b/agents-api/agents_api/web.py @@ -58,14 +58,13 @@ def make_exception_handler(status_code: int) -> Callable[[Any, Any], Any]: """ async def _handler(request: Request, exc: Exception): - location = None offending_input = None # Return the deepest matching possibility if isinstance(exc, (ValidationError, RequestValidationError)): errors = exc.errors() - + # Get the deepest matching errors max_depth = max(len(error["loc"]) for error in errors) errors = [error for error in errors if len(error["loc"]) == max_depth] @@ -97,7 +96,7 @@ async def _handler(request: Request, exc: Exception): break offending_input = offending_input[loc] - + # Keep only the message from the error errors = [error.get("msg", error) for error in errors]