This reminds me a bit of something I read about being in a video game once. Basically, it threw back copies of the last attack that hit it (and only the last attack), whether that was an axe, a lightning bolt, or a thrown cat. (Or a troll's tongue attack, because apparently trolls do that in this game.) It was a sort of puzzle boss; you need to make sure that it only possessed weak attacks to hit you with.

Something like that could work for your idea. This has the added benefit of giving the players more agency; a little planning allows the players to still use high-level spells and leave the boss unable to muster more than a copied cantrip.