[Bug] Assistant API returns malformed JSON despite response_format=json_object

Description

When using the new response_format parameter with json_object in the Assistant API or Playground, the model sometimes returns invalid JSON. The output often includes extra text, trailing explanations, or Markdown code blocks, which breaks JSON parsing in downstream applications.

Steps to Reproduce

  1. Use the Assistant API or Playground with a system prompt that instructs the model to return JSON only.
  2. Set response_format: {"type": "json_object"}.
  3. Call the model with a prompt requesting structured JSON data.
  4. Observe that the output still contains extra text or invalid syntax.

Expected Result

The model should return a single valid JSON object, with no text before or after.

Actual Result

The output sometimes:

  • Contains additional explanations before the JSON.
  • Uses Markdown code blocks.
  • Has trailing commas or partial objects.

Impact

This breaks json.loads in Python or equivalent parsers in other languages. I have to write extra sanitizing code to clean it up.

Environment

  • Assistant API and ChatGPT Playground
  • Model: GPT-4, GPT-4 Turbo, GPT-4o-mini
  • Observed June 2025

Additional Context

This happens even if I am very explicit in my system prompt to produce JSON only.

Suggested Priority

Medium - affects production workflows when relying on structured output.

1 Like

I’m seeing the same thing where the response will contain ```json markdown even if I specify a JSON object response. I get around it by providing the instructions to start the response with {. That seems to work but I don’t think I can rely on it.