Duplicated json with json mode

Have you guys ever received this weird duplicated response?

{
  "key": "..." // this is actually any object in the proper format
}

{
  "key": "..." // this is the unexpected duplication
}

Instead of receiving only the valid JSON object, sometimes I receive this duplicated answer, breaking my parsing :confused:

Similar has been reported before. The fault is the AI not emitting its stop sequence when it should, but instead continuing on more text production. It seems to be expressed more with the enforcement and limited sampling controls in “JSON-mode” model response.

If you do not have a nested object being returned, you can set the closing curly brace as the stop sequence API parameter, and then add it yourself. A stop being produced terminates the AI output and doesn’t provide the output token sequence specified (or its logprob).