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
- Use the Assistant API or Playground with a system prompt that instructs the model to return JSON only.
- Set
response_format: {"type": "json_object"}
. - Call the model with a prompt requesting structured JSON data.
- 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.