Forced function calling making up values for required parameters

Hi, I’m using function calling with tool_choice set to required.

Model: gpt-4o-0806
A sample request:

{
	"messages": [
		{
			"role": "user",
			"content": "What is 1+1"
		}
	],
	"model": "gpt-4o-0806",
	"temperature": 0,
	"tool_choice": "required",
	"tools": [
		{
			"type": "function",
			"function": {
				"name": "get_weather",
				"strict": true,
				"parameters": {
					"type": "object",
					"properties": {
						"location": {
							"type": "string"
						},
						"unit": {
							"type": "string",
							"enum": [
								"c",
								"f"
							]
						}
					},
					"required": [
						"location",
						"unit"
					],
					"additionalProperties": false
				}
			}
		},
		{
			"type": "function",
			"function": {
				"name": "get_stock_price",
				"strict": true,
				"parameters": {
					"type": "object",
					"properties": {
						"symbol": {
							"type": "string"
						}
					},
					"required": [
						"symbol"
					],
					"additionalProperties": false
				}
			}
		}
	]
}

Response:

{
	"choices": [
		{
			"content_filter_results": {},
			"finish_reason": "stop",
			"index": 0,
			"logprobs": null,
			"message": {
				"content": null,
				"role": "assistant",
				"tool_calls": [
					{
						"function": {
							"arguments": "{\"location\":\"New York\",\"unit\":\"c\"}",
							"name": "get_weather"
						},
						"id": "call_3AttvQPe3fm6QHplq6th27jq",
						"type": "function"
					}
				]
			}
		}
	]
}

Model is making up values for required parameters, please advise how to solve the problem?

1 Like

I think because you have the tool_required parameter set to true, it is forcing itself to use one of the tools you have defined in your function calling to answer the question. Due to this,
the model is approximating the closest function or defaulting to the first one and returning the output accordingly.

If you remove it from required, you should get the correct answers back

2 Likes

Thanks, but if we don’t use tool_choice: required, how can we enforce Open AI to only respond by calling provided functions, and not to use its own knowledge base?

1 Like

That’s fair, but the question also needs to be in line with the functions so that it can try and answer them.

Based on your shared input, the sent messages were 1+1. which did not fit in with any of the functions which were provided by you, thus causing the discrepancy

1 Like