-
Notifications
You must be signed in to change notification settings - Fork 515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tools with nested properties getting cut short #429
Comments
Hey! Thanks for pointing this out. I saw you mentioned that the server did this too - we should definitely address this on the SDK end. Have you tried the same behavior through a curl request on the server too? |
I had to learn to use the REST API to test it with my input, but yes I can confirm that this is also still happening on the backend server. Here is my curl request (Windows CMD Prompt): Contents of json.txt:
Raw return from the Ollama server running in the CMD line with OLLAMA_DEBUG=1: The raw prompt formatted for readability:
The output returned to curl command: As for what's going on in the backend, I'm not too well versed in Golang so I don't really know. However, I would guess it has something to do with the Tools structure definitions in the ollama/api/types.go file:
Most notably this struct:
Which is inline with the "cut-off point" we are getting in the server debug raw prompt. I'm guessing it just needs to be made, like, recursively deep... |
Okay this is really good for me to know. I also plan on having structured outputs for tool calling so it'll end up looking much better (hopefully!). I get a fix on this in after some of the new engine work - which is also structured outputs. I'm curious though - what has your experience been with nested tools? I'd imagine that the reliability is pretty low. |
Thanks! And hmmmm, I haven't really tried tool calling work outside of ollama, and you already know how nested tools come out (just results in invalid pydantic validation errors due to missing attributes from the truncation). What I can add is that in order to work within that limitation I needed a workaround that went away from the pydantic method of defining complex tools and just passed the tool as a dictionary. But the dictionary would still be three levels or so deep, I would just jam the extra "dimensions" needed into the innermost description. Kinda hacky. In the case I provided where the final cut-off is a list if analyst, my dictionary would look something like:
At least with llama3.1, this would return a consistent enough json string I could unmarshall (but this is after some serious cleaning, sanitation, and json repair for edge cases. So far not the most reliable but can deliver a complete workflow 😅. I imagine quality would be better with the formal fix. |
Yeah this isn't ideal for sure. Have you tried trying out structured outputs instead of tool calling instead? I think it might fit your case better. The extra work you'd have to do would be to unmarshal the returned JSON and then execute a tool given that. Maybe give this a look in the meantime? https://ollama.com/blog/structured-outputs |
I'll take a look at it meanwhile. Haven't really looked into it. Thanks for the recommendation. |
Just as the title says, I believe tools set up with pydantic are having their deeper "nests" cut off before being sent to ollama.
Take this example tool definition from the Langgraph course:
This should produce a unprocessed tool JSON object along the lines of
However, the tool object that comes out of the the Tool.model_validate() method in ollama's _client.py module is similar to the following structure:
I am unsure if this is a pydantic issue, or one caused by the Tool definition in ollama's _types.py module:
I also know that the Ollama server itself also did this sort of JSON truncation even if the full tool was given to it. I do not know if this has been fixed at that level, but at least the given tool in the client chat request should be one that represents the full tool and all its nested properties. Earlier versions of ollama.py did not cut truncate the tool structure at this stage, so I would consider this a bug.
The text was updated successfully, but these errors were encountered: