To pull a rabbit out of a hat

“To pull a rabbit out of a hat” means that you produce something seemingly out of nowhere or do something unexpected but ingeniously effective in response to a problem.