1 out of 5 calls results in strange responses when using function calls

I am getting strange responses when using function calls, it is random, and only occurring 1 in 5 times with the same prompts.

Below is the response:

	"id": "chatcmpl-",
	"model": "gpt-4o-2024-05-13",
	"usage": {
		"totalTokens": 7030,
		"promptTokens": 2934,
		"completionTokens": 4096
	"object": "chat.completion",
	"choices": [
			"index": 0,
			"message": {
				"role": "assistant",
				"content": "\n\n\n\n\n\n                             \n                              \n\n\n                              \n\n\n\n\n\n\n\n                               \n\n                               \n\n\n\n\n                             \n\n\n                             \n\n\n\n\n\n\n                              \n                               \n\n\n\n\n\n\n                             \n\n\n                               \n\n\n\n                              \n\n\n                               \n\n\n\n\n                              \n\n                                \n\n\n\n\n                              \n\n\n                               \n\n\n\n\n\n                              \n\n\n\n\n\n                              \n\n\n\n                               \n\n\n\n\n                              \n                               \n\n\n\n\n                             \n\n\n                              \n\n                              \n\n\n\n\n                             \n\n\n                              \n\n\n\n\n\n\n\n                            \n\n\n                              \n\n\n                               \n\n\n\n                              \n\n                                 \n\n\n\n                              \n\n\n\n                               \n\n\n                             \n\n\n\n\n\n                                \n                              \n\n\n\n                                \n                             \n\n\n                              \n\n\n\n\n                                \n                               \n\n\n\n\n\n                                \n                             \n\n\n\n\n                              \n\n\n                               \n\n\n\n                                \n                              \n\n                                \n\n\n\n\n                                \n                                \n\n\n\n\n\n\n\n                                \n                                \n\n\n\n                                \n                               \n\n\n\n\n\n                               \n                                 \n\n\n\n                                \n                                  \n                                \n                               \n\n\n\n\n\n                              \n                                 \n\n                                \n                                  \n                                  \n                                  \n                                  \n\n\n\n\n                               \n                                 \n                                   \n                                    \n                               \n\n\n\n\n                                \n\n\n\n                                  \n                                  \n                                   \n\n\n                                 \n                                  \n\n                                   \n                                  \n                              \n\n\n\n\n\n                               \n                               \n\n\n\n\n\n\n\n                             \n                              \n\n\n\n                                \n\n\n                                 \n\n                                \n                                     \n                                 \n\n\n                               \n                              \n                               \n                                  \n                                     \n                               \n \n   \n                                       \n\n\n\n\n\n                                \n\n\n                               \n                                  \n                                    \n                                \n                               \n                             \n                                 \n\n                                    \n                               \n                                \n\n\n\n\n                              \n                                \n                              \n                             \n\n                                 \n                               \n                                   \n                                \n                                 \n\n\n                              \n                                \n                                \n\n                                   \n\n\n                                    \n                               \n                                \n\n\n                                 \n\n\n                              \n                                \n                                    \n\n\n                                    \n                                  \n                                \n\n\n\n\n                                 \n\n\n                               \n                                  \n                                 \n                                   \n                                      \n                                \n                                     \n                             \n\n\n\n                                \n\n\n                                   \n                                 \n\n\n\n\n\n\n                                  \n                               \n                                      \n                               \n                                 \n",
				"toolCalls": [],
				"functionCall": null
			"finishReason": "length"
	"created": 1718361253,
	"systemFingerprint": "fp_319be4768e"
1 Like

From my experience, GPT-4o is a little unreliable with function calls, especially at higher temperatures (1 and above). Lowering it can help, also you might want to change your system prompt to very explicitly explain the function calls to the AI so it doesn’t get confused — you really gotta be clear with 4o about this stuff.