New Tool Calling issues. #169

Closed
opened 2026-02-15 16:28:28 -05:00 by yindo · 2 comments
Owner

Originally created by @AssassinUKG on GitHub (Nov 26, 2024).

What is the issue?

In my image below you can see me using the code functions provided by the ollama python examples on GitHub, specifically the tools.py example (added client for local ollama)

Sometimes the values are treated as strings and other times as integer, although the function definition is an int type.

def add_two_numbers(a: int, b: int) -> int:
  """
  Add two numbers

  Args:
    a (int): The first number
    b (int): The second number

  Returns:
    int: The sum of the two numbers
  """
  return a + b

image

How to resolve this as other tools will likely suffer the same issue.

OS

Windows

GPU

Nvidia

CPU

AMD

Ollama version

ollama version is 0.4.5

Originally created by @AssassinUKG on GitHub (Nov 26, 2024). ### What is the issue? In my image below you can see me using the code functions provided by the ollama python examples on GitHub, specifically the tools.py example (added client for local ollama) Sometimes the values are treated as strings and other times as integer, although the function definition is an int type. ```python def add_two_numbers(a: int, b: int) -> int: """ Add two numbers Args: a (int): The first number b (int): The second number Returns: int: The sum of the two numbers """ return a + b ``` ![image](https://github.com/user-attachments/assets/2e8e409f-76ec-4a91-a679-8d9b4bb70410) How to resolve this as other tools will likely suffer the same issue. ### OS Windows ### GPU Nvidia ### CPU AMD ### Ollama version ollama version is 0.4.5
yindo closed this issue 2026-02-15 16:28:28 -05:00
Author
Owner

@ParthSareen commented on GitHub (Nov 26, 2024):

So since function calling from the model doesn't check types (and python is not strongly typed) - that's something the user has to do unfortunately. Based on my testing small models often return correctly typed data just wrapped within a string. I'd recommend typechecking/pulling the data into your desired format.

You can either structure that in your function calling code.
E.g.

if function_to_call == add_two_numbers:
    print('Function output:', function_to_call(a=int(tool.function.arguments['a']), b=int(tool.function.arguments['b'])))

Or within the function:

def add two_...:
  a = int(a)
  b = int(b)

IMO the first option is better as you can make helper type checking functions. Appreciate you bringing this up though! Probably helpful for new users!

@ParthSareen commented on GitHub (Nov 26, 2024): So since function calling from the model doesn't check types (and python is not strongly typed) - that's something the user has to do unfortunately. Based on my testing small models often return correctly typed data just wrapped within a string. I'd recommend typechecking/pulling the data into your desired format. You can either structure that in your function calling code. E.g. ```py if function_to_call == add_two_numbers: print('Function output:', function_to_call(a=int(tool.function.arguments['a']), b=int(tool.function.arguments['b']))) ``` Or within the function: ```py def add two_...: a = int(a) b = int(b) ``` IMO the first option is better as you can make helper type checking functions. Appreciate you bringing this up though! Probably helpful for new users!
Author
Owner

@AssassinUKG commented on GitHub (Nov 26, 2024):

Many Thanks @ParthSareen Appriciate the example and reply 👍

@AssassinUKG commented on GitHub (Nov 26, 2024): Many Thanks @ParthSareen Appriciate the example and reply 👍
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#169