The only way I managed to work around that issue was by introducing a supervisor agent. This supervisor agent receives the output from the primary agent and transforms it into a properly formatted JSON.