mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 09:05:23 -04:00
Tools not working when providing a schema via format=...
#282
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @AlexysGromard on GitHub (Jul 31, 2025).
Description
When using a function tool with a response model and providing its schema via the
formatargument, the tool is never invoked. The same code works whenformatis omitted, but breaks when a schema is passed usingmodel_json_schema()from a Pydantic model.Code to Reproduce
Observed Behavior
format=...: No tool call is made,response.message.tool_callsis empty.format=...: The functionadd_two_numbersis correctly triggered and returns the result.Expected Behavior
Providing a schema via
format=AddTwoNumbersOutput.model_json_schema()should not prevent tool calls from being triggered.My Environment
llama3.1@lennartpollvogt commented on GitHub (Aug 2, 2025):
I would like to keep it that way. I only use the model schema in format when I want to force the LLM to adhere to it, and it shouldn't have the possibility to call a tool. Otherwise the reliability would decrease.
But maybe you can explain what why you would expect the behavior you've described? Which use cases do you have where this would be necessary?
@zeerd commented on GitHub (Sep 3, 2025):
The example given is not very good.
In fact, in the vast majority of cases, we do not know when LLM will complete all tool call processes and begin outputting the final results.
The real progress would be like below:
The last
chat(tools=[...])that givereswithouttool_callsin theloopwill give the final answer without format.User need to
chatagain withformats=[...]for the formatted answer.This is a waste of tokens.
@ParthSareen commented on GitHub (Sep 18, 2025):
We're probably not going to support structured generation around tool calling for now. It's best to use a model better at tool calling. I will be working on erroring better so that the error can be used to inform the model about the incorrect call.