Skip to content

Conversation

jmorganca
Copy link
Member

@jmorganca jmorganca commented Jun 28, 2025

Tool call parsing was not correctly handling "arguments": {}, or considering required fields.

Fixes #11232

@jmorganca jmorganca requested a review from ParthSareen June 28, 2025 18:28
@jmorganca jmorganca force-pushed the jmorganca/tool-calling-fixes branch 3 times, most recently from b9a2cea to 8e01c60 Compare June 28, 2025 18:44
@jmorganca jmorganca force-pushed the jmorganca/tool-calling-fixes branch from 8e01c60 to 21a253c Compare June 28, 2025 20:00
tools/tools.go Outdated
Comment on lines 218 to 231
// check for required parameters
if valid {
for _, required := range tool.Function.Parameters.Required {
if _, exists := obj[required]; !exists {
valid = false
break
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So does the user get the tool call as a JSON instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the test it seems like we don't return anything. Might want to error out instead

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great point! Ollama should error if invalid parameters are sent to the tool (similar to other APIs). I added a TODO and we should fix this in the near future

Copy link

@Tarmenale2 Tarmenale2 Jun 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the test it seems like we don't return anything. Might want to error out instead

If you refer to ticket #11232 then please note that Qwen3 produced correct output, but Ollama converted it into incorrect JSON call request, so... one thing is to read correctly what was produced by model (this is what I've reported and it is important) and second thing is to validate if model followed tool definition (which is sounds like nice improvement, but in my mind it is low priority thing and might be challenging how to handle it correctly).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tarmenale2 indeed, errors will be added in a follow up. This PR fixes the tool parsing issue you noticed in #11232

@jmorganca jmorganca force-pushed the jmorganca/tool-calling-fixes branch 2 times, most recently from 0a4186b to 56e32ec Compare June 28, 2025 23:40
@jmorganca jmorganca force-pushed the jmorganca/tool-calling-fixes branch from 56e32ec to 3a38f7e Compare June 29, 2025 00:06
@jmorganca jmorganca merged commit 44b17d2 into main Jun 30, 2025
8 checks passed
@jmorganca jmorganca deleted the jmorganca/tool-calling-fixes branch June 30, 2025 15:59
gabe-l-hart added a commit to gabe-l-hart/ollama that referenced this pull request Jul 11, 2025
* origin/main:
ggml: Report ordinal IDs for AMD GPUs on Windows
doc: add MacOS docs (ollama#11334)
Reduce default parallelism to 1 (ollama#11330)
API/CLI context enhancements (ollama#11331)
add `tool_name` to api.md (ollama#11326)
template: add tool result compatibility (ollama#11294)
ci: modularization (ollama#11324)
Revert "ggml: Temporarily disable reporting UUIDs"
readme: update Ollama icon size
int: add performance integration tests (ollama#11173)
doc: add NVIDIA blackwell to supported list (ollama#11307)
Update base image to Ubuntu 24.04 LTS (ollama#9681)
doc: Update link for mac install (ollama#11288)
mimic logs for layers on new engine (ollama#11278)
readme: add NativeMind to community integrations (ollama#11242)
tools: fix parsing tool calls with empty arguments, missing required fields (ollama#11233)
readme: add ollama-bash-toolshed to community integrations (ollama#11224)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parser generates incorrect tool calls compared to Qwen3 model output
3 participants