# JSON mode vs Function Calling

**URL:** <https://community.openai.com/t/json-mode-vs-function-calling/476994>\
**Category:** API\
**Tags:** json, functions, function-calling, json-mode\
**Created:** [November 7, 2023, 4:45am UTC](https://community.openai.com/t/json-mode-vs-function-calling/476994 "2023-11-07T04:45:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![omar\_t](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/omar_t/32/206828_2.png) [@omar\_t](https://community.openai.com/u/omar_t)\
**Post date:** [November 7, 2023, 4:45am UTC](https://community.openai.com/t/json-mode-vs-function-calling/476994/1 "2023-11-07T04:45:42Z")

</div>

Trying to understand the trade offs between when to use JSON mode instead of Function Calling?  
The documentation says JSON mode will always produce valid JSON. And at the same time it says Function Calling is “more likely” to return the right function parameters than in the previous models.

Previously I was using function calling to get JSON from the GPT models (using the function\_call parameter) and occasionally it would give me invalid JSON. If I require valid JSON should I swap out my current function calling approach for the JSON mode in order to get 100% valid JSON then?

---

<div class="post-metadata">

**Author:** ![udm17](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/udm17/32/139530_2.png) [@udm17](https://community.openai.com/u/udm17)\
**Post date:** [November 7, 2023, 6:25am UTC](https://community.openai.com/t/json-mode-vs-function-calling/476994/2 "2023-11-07T06:25:58Z")

</div>

Using the JSON mode, which is an inbuilt feature specifically for the purpose of creating a JSON, makes more sense in your situation.

Don’t forget to add the line 'Return the output as JSON" to the system prompt when using the mode, so that the ystem does not throw up an error

---

<div class="post-metadata">

**Author:** ![nikola1jankovic](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/nikola1jankovic/32/36961_2.png) [@nikola1jankovic](https://community.openai.com/u/nikola1jankovic)\
**Post date:** [November 7, 2023, 7:45am UTC](https://community.openai.com/t/json-mode-vs-function-calling/476994/3 "2023-11-07T07:45:48Z")

</div>

Does it consistently return the same JSON structure?

---

<div class="post-metadata">

**Author:** ![udm17](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/udm17/32/139530_2.png) [@udm17](https://community.openai.com/u/udm17)\
**Post date:** [November 7, 2023, 7:51am UTC](https://community.openai.com/t/json-mode-vs-function-calling/476994/4 "2023-11-07T07:51:16Z")

</div>

For me, it’s been fairly consistent today. Haven’t had any problems or exceptions thrown

---

<div class="post-metadata">

**Author:** ![owencmoore](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/owencmoore/32/146905_2.png) [@owencmoore](https://community.openai.com/u/owencmoore)\
**Post date:** [November 7, 2023, 6:18pm UTC](https://community.openai.com/t/json-mode-vs-function-calling/476994/5 "2023-11-07T18:18:17Z")

</div>

(I work on JSON mode at OpenAI)

JSON mode is **always enabled** for the generation of function arguments, so those are guaranteed to parse.

JSON mode is **opt in** for regular messages.

Note that JSON mode sadly doesn’t guarantee that the output will match your schema (though the model tries to do this and is continually getting better at it), only that it is JSON that will parse.

So TL;DR is that you can use either functions or messages, and in both cases know you will get parseable JSON back 👍

---

<div class="post-metadata">

**Author:** ![kjordan](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/kjordan/32/157616_2.png) [@kjordan](https://community.openai.com/u/kjordan)\
**Post date:** [November 8, 2023, 3:55am UTC](https://community.openai.com/t/json-mode-vs-function-calling/476994/6 "2023-11-08T03:55:25Z")

</div>

Appreciate your work, JSON mode solves so many problems parsing the JSON responses, especially the unescaped symbols. Good work ❤

---

<div class="post-metadata">

**Author:** ![360macky](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/360macky/32/742276_2.png) [@360macky](https://community.openai.com/u/360macky)\
**Post date:** [November 25, 2023, 2:36am UTC](https://community.openai.com/t/json-mode-vs-function-calling/476994/7 "2023-11-25T02:36:42Z")

</div>

Amazing! Thank you @owencmoore

---

<div class="post-metadata">

**Author:** ![alex0pereira](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/alex0pereira/32/245516_2.png) [@alex0pereira](https://community.openai.com/u/alex0pereira)\
**Post date:** [December 16, 2023, 6:04am UTC](https://community.openai.com/t/json-mode-vs-function-calling/476994/8 "2023-12-16T06:04:52Z")

</div>

Hello,  
I still have such issues (not valid JSON or completely other format) on around 10 to 20% of my function calls.

Example function :

 ![image](https://us1.discourse-cdn.com/openai1/original/4X/3/8/e/38e2681cf9fc2408ddaf2c71010a717a6f4ed21e.png)

Should return a json with field “command” inside.  
I have in return the format below, which is incorrect and not parseable.

 ![image](https://us1.discourse-cdn.com/openai1/original/4X/2/a/5/2a5491ca923953243881494396394b091f94e60e.png)

Any help on this ?

---

<div class="post-metadata">

**Author:** ![EricGT](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/ericgt/32/20571_2.png) [@EricGT](https://community.openai.com/u/EricGT)\
**Post date:** [December 16, 2023, 3:54pm UTC](https://community.openai.com/t/json-mode-vs-function-calling/476994/9 "2023-12-16T15:54:57Z")

</div>

As this topic has a noted [solution](https://community.openai.com/t/json-mode-vs-function-calling/476994/5) closing this topic.

Please open a new topic for new questions.

---

<div class="post-metadata">

**Author:** ![EricGT](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/ericgt/32/20571_2.png) [@EricGT](https://community.openai.com/u/EricGT)\
**Post date:** [December 16, 2023, 3:55pm UTC](https://community.openai.com/t/json-mode-vs-function-calling/476994/10 "2023-12-16T15:55:01Z")

</div>


