Add allow_unsafe check

Adding a allow_unsafe check in sanitize function.