Raise valueerror instead of using assert for production code