here is code (with several examples) that takes it a couple steps further by validating the output json and pydantic model and providing feedback to the llm model when it gets either of those wrong:
https://github.com/jiggy-ai/pydantic-chatcompletion/blob/mas...