Visual formatting tokens "\n" and "\t" aren't needed when response format is JSON Object

Hello there,

When response_format={ "type": "json_object" }, the output is formatted to be visually appealing.

Here is an example passage from the latest JSON output:
\t\t{\n\t\t\t"image_key": "#0",\n\t\t\t"is_history": "true",\n\t\t\t"reason": "This image shows the iconic façade of The Treasury (Al-Khazneh) at Petra, with people gathered around it, which fits perfectly with the report on Petra\'s historical and archaeological significance."\n

The system is adding “\n” and “\t”. They are not needed in API calls. My last request with JSON output had 5535 characters and 545 were formatting characters. Removing those would yield 9.84% in token savings.

3 Likes

It’s just a guess, but maybe this formatting helps the model to better understand the JSON structure? Most of its training data might be in this form. Would be interesting to compare model precision for both styles.

2 Likes

Perhaps they could add a parameter called pretty_json?

I like it for easy troubleshooting and visualising, but I totally agree that it’s unnecessary in a production setting.

2 Likes