Hey! I ran into the same issues. In order to fix the invalid output you can specify to ChatGPT that you want to recieve the response as a JSON formatted text.
I was a bit lazy, so I just inform the user to re-run it manually instead of automatically handling it.