I gave this suggestion in Discord, posting in here so it isn't lost.
A possible solution, instead of going into the coding to cause it to cancel during a spell action (which might have more variables, and could get wonky), would be causing a caster's spell failure (both arcane and divine) to be at 100% while in Expertise mode. This would solve the problem.
Fighters don't care, so having it just apply whenever expertise is on would stop casters, but have no impact on fighters.
The only issue I could see is, if a mage still has expertise for some reason (such as a hybrid melee/caster) and toggles it on and off, if there might be the possibility of that 100% spell failure not going away.