My first thought was can you get the LLM to generate the pattern first, and then the completion?
In general, it seems like building a production-ready LLM-based application requires _a lot_ of these little tricks and methods to hammer results into shape before sending them downstream.