In case you're using OpenRouter, check out their new Response Healing feature that claims to solve exactly this issue.
https://openrouter.ai/announcements/response-healing-reduce-...