[GH-ISSUE #9768] API Tool arguments formatting issue #118950

Closed
opened 2026-05-20 20:10:12 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @Seniorsimo on GitHub (Feb 10, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/9768

Bug Report

Installation Method

Docker

Environment

  • Open WebUI Version: v0.5.10

  • Ollama (if applicable): 0.5.7-0-ga420a45-dirty

  • Operating System: Windows 11

Confirmation:

  • I have read and followed all the instructions provided in the README.md.
  • I am on the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
  • I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below.

Expected Behavior:

When calling the Open-webUI API with tools that need arguments and an expected tool call is expected, the model answer with a tool call with arguments

Actual Behavior:

The tool call answered has the arguments not correctly serialized

Description

Bug Summary:
The JSON representazion of the arguments in the tool beign called seem a standard python representation of a dictionary and not a full serialized json.

A sample tool call returned by Open-webUI

	"tool_calls": [
		{
			"index": 0, 
			"id": "call_df2ee15e-e8ee-4709-b179-e0f2df19fa91", 
			"type": "function", 
			"function": {
				"name": "weather", 
				"arguments": "{'city': 'New York'}"
			}
		}
	]

A sample tool call returned by OpenAI

	"tool_calls":[
		{
			"index":0,
			"id":"call_Gs5yB8tdaYWth1RFMbeIEVDU",
			"type":"function",
			"function":{
				"name":"weather",
				"arguments":"{\"city\":\"New York\"}"
			}
		}
	]

In the Open-webUI the arguments is not a well-formed JSON: ' should be replaced by \".

Reproduction Details

Steps to Reproduce:

Open-webui

Request

curl -XPOST -H 'Authorization: Bearer sk-YOUR-API-KEY' -H "Content-type: application/json" -d '{
	"messages": [
		{
			"content": "You are a helpful assistant", 
			"role": "system"
		}, {
			"content": "It feels so cold today in NY.", 
			"role": "user"
		}
	], 
	"model": "pc.qwen2.5:14b", 
	"n": 1, 
	"stream": true, 
	"temperature": 0.7, 
	"tools": [
		{
			"type": "function", 
			"function": {
				"name": "weather", 
				"description": "Retrieve the weather for a city.", 
				"parameters": {
					"properties": {
						"city": {
							"description": "The city to inspect current weather", 
							"type": "string"
						}
					}, 
					"required": ["city"], 
					"type": "object"
				}
			}
		}
	]
}' 'http://localhost:8080/api/chat/completions'

Response

{
	"id": "qwen2.5:14b-92f77e7e-baa5-454a-aa84-4a8647ef3044", 
	"created": 1739210359, 
	"model": "qwen2.5:14b", 
	"choices": [
		{
			"index": 0, 
			"logprobs": null, 
			"finish_reason": null, 
			"delta": {
				"tool_calls": [
					{
						"index": 0, 
						"id": "call_df2ee15e-e8ee-4709-b179-e0f2df19fa91", 
						"type": "function", 
						"function": {
							"name": "weather", 
							"arguments": "{'city': 'New York'}"
						}
					}
				]
			}
		}
	], 
	"object": "chat.completion.chunk"
}

OpenAI

Request

curl -XPOST -H 'Authorization: Bearer sk-YOUR-API-KEY' -H "Content-type: application/json" -d '{
    "model": "gpt-3.5-turbo",
    "messages": [
		{
			"content": "You are a helpful assistant", 
			"role": "system"
		}, {
			"content": "It feels so cold today in NY.", 
			"role": "user"
		}
	],
	"stream": true, 
	"temperature": 0.7, 
	"tools": [
		{
			"type": "function", 
			"function": {
				"name": "weather", 
				"description": "Retrieve the weather for a city.", 
				"parameters": {
					"properties": {
						"city": {
							"description": "The city to inspect current weather", 
							"type": "string"
						}
					}, 
					"required": ["city"], 
					"type": "object"
				}
			}
		}
	]
}' 'https://api.openai.com/v1/chat/completions'

Response

{
	"id":"chatcmpl-AzA1wy4pXHFTtPGVjcZ4F04XUAfK0",
	"object":"chat.completion.chunk",
	"created":1739139928,
	"model":"gpt-3.5-turbo-0125",
	"service_tier":"default",
	"system_fingerprint":null,
	"choices":[
		{
			"index":0,
			"delta":{
				"role":"assistant",
				"content":null,
				"tool_calls":[
					{
						"index":0,
						"id":"call_Gs5yB8tdaYWth1RFMbeIEVDU",
						"type":"function",
						"function":{
							"name":"weather",
							"arguments":"{\"city\":\"New York\"}"
						}
					}
				]
			},
			"logprobs":null,
			"finish_reason":null
		}
	]
}

Logs and Screenshots

Browser Console Logs:
not applicable

Docker Container Logs:
INFO: 10.88.5.1:0 - "POST /api/chat/completions HTTP/1.1" 200 OK

Screenshots/Screen Recordings (if applicable):
not applicable

Additional Information

I have tried to solve this locally in a fork and seems working now.
Just replaced tis line:

	"arguments": f"{tool_call.get('function', {}).get('arguments', {})}",

with this one:

	"arguments": json.dumps(tool_call.get('function', {}).get('arguments', {})),

The related commit:
2c04be429a

Let me know if some other info is needed.

Great work !!!

Originally created by @Seniorsimo on GitHub (Feb 10, 2025). Original GitHub issue: https://github.com/open-webui/open-webui/issues/9768 # Bug Report ## Installation Method Docker ## Environment - **Open WebUI Version:** v0.5.10 - **Ollama (if applicable):** 0.5.7-0-ga420a45-dirty - **Operating System:** Windows 11 **Confirmation:** - [x] I have read and followed all the instructions provided in the README.md. - [x] I am on the latest version of both Open WebUI and Ollama. - [x] I have included the browser console logs. - [x] I have included the Docker container logs. - [x] I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below. ## Expected Behavior: When calling the Open-webUI API with tools that need arguments and an expected tool call is expected, the model answer with a tool call with arguments ## Actual Behavior: The tool call answered has the arguments not correctly serialized ## Description **Bug Summary:** The JSON representazion of the arguments in the tool beign called seem a standard python representation of a dictionary and not a full serialized json. A sample tool call returned by Open-webUI ```json "tool_calls": [ { "index": 0, "id": "call_df2ee15e-e8ee-4709-b179-e0f2df19fa91", "type": "function", "function": { "name": "weather", "arguments": "{'city': 'New York'}" } } ] ``` A sample tool call returned by OpenAI ```json "tool_calls":[ { "index":0, "id":"call_Gs5yB8tdaYWth1RFMbeIEVDU", "type":"function", "function":{ "name":"weather", "arguments":"{\"city\":\"New York\"}" } } ] ``` In the Open-webUI the arguments is not a well-formed JSON: `'` should be replaced by `\"`. ## Reproduction Details **Steps to Reproduce:** *Open-webui* Request ```bash curl -XPOST -H 'Authorization: Bearer sk-YOUR-API-KEY' -H "Content-type: application/json" -d '{ "messages": [ { "content": "You are a helpful assistant", "role": "system" }, { "content": "It feels so cold today in NY.", "role": "user" } ], "model": "pc.qwen2.5:14b", "n": 1, "stream": true, "temperature": 0.7, "tools": [ { "type": "function", "function": { "name": "weather", "description": "Retrieve the weather for a city.", "parameters": { "properties": { "city": { "description": "The city to inspect current weather", "type": "string" } }, "required": ["city"], "type": "object" } } } ] }' 'http://localhost:8080/api/chat/completions' ``` Response ```json { "id": "qwen2.5:14b-92f77e7e-baa5-454a-aa84-4a8647ef3044", "created": 1739210359, "model": "qwen2.5:14b", "choices": [ { "index": 0, "logprobs": null, "finish_reason": null, "delta": { "tool_calls": [ { "index": 0, "id": "call_df2ee15e-e8ee-4709-b179-e0f2df19fa91", "type": "function", "function": { "name": "weather", "arguments": "{'city': 'New York'}" } } ] } } ], "object": "chat.completion.chunk" } ``` *OpenAI* Request ```bash curl -XPOST -H 'Authorization: Bearer sk-YOUR-API-KEY' -H "Content-type: application/json" -d '{ "model": "gpt-3.5-turbo", "messages": [ { "content": "You are a helpful assistant", "role": "system" }, { "content": "It feels so cold today in NY.", "role": "user" } ], "stream": true, "temperature": 0.7, "tools": [ { "type": "function", "function": { "name": "weather", "description": "Retrieve the weather for a city.", "parameters": { "properties": { "city": { "description": "The city to inspect current weather", "type": "string" } }, "required": ["city"], "type": "object" } } } ] }' 'https://api.openai.com/v1/chat/completions' ``` Response ```json { "id":"chatcmpl-AzA1wy4pXHFTtPGVjcZ4F04XUAfK0", "object":"chat.completion.chunk", "created":1739139928, "model":"gpt-3.5-turbo-0125", "service_tier":"default", "system_fingerprint":null, "choices":[ { "index":0, "delta":{ "role":"assistant", "content":null, "tool_calls":[ { "index":0, "id":"call_Gs5yB8tdaYWth1RFMbeIEVDU", "type":"function", "function":{ "name":"weather", "arguments":"{\"city\":\"New York\"}" } } ] }, "logprobs":null, "finish_reason":null } ] } ``` ## Logs and Screenshots **Browser Console Logs:** not applicable **Docker Container Logs:** INFO: 10.88.5.1:0 - "POST /api/chat/completions HTTP/1.1" 200 OK **Screenshots/Screen Recordings (if applicable):** not applicable ## Additional Information I have tried to solve this locally in a fork and seems working now. Just replaced tis line: ```python "arguments": f"{tool_call.get('function', {}).get('arguments', {})}", ``` with this one: ```python "arguments": json.dumps(tool_call.get('function', {}).get('arguments', {})), ``` The related commit: https://github.com/open-webui/open-webui/commit/2c04be429a720b6d4921c73ef944fa4067cabad1 Let me know if some other info is needed. Great work !!!
Author
Owner

@tjbck commented on GitHub (Feb 10, 2025):

This is model dependent and out of scope of Open WebUI.

<!-- gh-comment-id:2648994126 --> @tjbck commented on GitHub (Feb 10, 2025): This is model dependent and out of scope of Open WebUI.
Author
Owner

@Seniorsimo commented on GitHub (Feb 10, 2025):

How could it be model-dependent? I've tried multiple models:

qwen2.5:14b (the one I posted)
llama3.2:latest
Even gpt-3.5-tbo using OpenWebUI as a proxy
In all cases, the results were identical.

From the code in my bug report, you can see that the current implementation is printing a dictionary instead of properly JSON serializing it. The method in question is called "ollama_to_openai," which suggests its purpose should be to convert Ollama responses into OpenAI-compatible standards.

If the API being exposed must be compatible with OpenAI, shouldn't I expect consistent results regardless of the model used? Additionally, even if a different model is employed, shouldn’t its response be converted to adhere to the OpenAI standard?

This fix literally 10 seconds to implement:

<!-- gh-comment-id:2649012601 --> @Seniorsimo commented on GitHub (Feb 10, 2025): How could it be model-dependent? I've tried multiple models: qwen2.5:14b (the one I posted) llama3.2:latest Even gpt-3.5-tbo using OpenWebUI as a proxy In all cases, the results were identical. From the code in my bug report, you can see that the current implementation is printing a dictionary instead of properly JSON serializing it. The method in question is called "ollama_to_openai," which suggests its purpose should be to convert Ollama responses into OpenAI-compatible standards. If the API being exposed must be compatible with OpenAI, shouldn't I expect consistent results regardless of the model used? Additionally, even if a different model is employed, shouldn’t its response be converted to adhere to the OpenAI standard? This fix literally 10 seconds to implement:
Author
Owner

@gmammolo commented on GitHub (Feb 10, 2025):

Hi @tjbck,

I confirm that I have experienced the same bug and that the suggested fix worked for me!
It's just a "parsing" bug, not a model problem.
Using <json.dumps> instead of a simple string f“” can easily solve the bug.

Thanks @Seniorsimo for the solution.

<!-- gh-comment-id:2649140636 --> @gmammolo commented on GitHub (Feb 10, 2025): Hi @tjbck, I confirm that I have experienced the same bug and that the suggested fix worked for me! It's just a "parsing" bug, not a model problem. Using <json.dumps> instead of a simple string f“” can easily solve the bug. Thanks @Seniorsimo for the solution.
Author
Owner

@tjbck commented on GitHub (Feb 10, 2025):

Addressed with 0f12c4d14f, Misread your issue post!

<!-- gh-comment-id:2649145442 --> @tjbck commented on GitHub (Feb 10, 2025): Addressed with 0f12c4d14f1eef01a221c58c2506d8215b26293c, Misread your issue post!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#118950