One of the frustrating aspects of using prompts to generate code is that the output can vary quite a bit even with the same prompt. Creating an API which use the OpenAI APIs for mission critical solutions feels a bit scary and unpredictable. For structured output, I know people use libraries like Pydantic with Python. I don't now the best approach to deal with this with regards to code generation, though. For now, I guess having an experienced software engineer examine the code is essential.