from fastapi import Request, status from fastapi.encoders import jsonable_encoder from fastapi.responses import JSONResponse async def validation_exception_handler(request: Request, exc: ValueError): return JSONResponse( status_code=status.HTTP_400_BAD_REQUEST, content=jsonable_encoder({"detail": exc.errors()}), )