Tool call doesn't honor the function definition when responding #194

Closed
opened 2026-02-15 16:28:38 -05:00 by yindo · 1 comment
Owner

Originally created by @2b3pro on GitHub (Dec 30, 2024).

Given this parameter definition in the function def:

'parameters': {'type': 'object', 'properties': {'weight_kg': {'type': 'number', 'description': 'Weight in kilograms'}, 'height_m': {'type': 'number', 'description': 'Height in meters'}}

The result is:

tool_call=Function(name='calculate_bmi', arguments={'height_m': '1.78', 'weight_kg': '78'})

…where the numbers are converted to strings. They should be numbers (floats).

Originally created by @2b3pro on GitHub (Dec 30, 2024). Given this parameter definition in the function def: `'parameters': {'type': 'object', 'properties': {'weight_kg': {'type': 'number', 'description': 'Weight in kilograms'}, 'height_m': {'type': 'number', 'description': 'Height in meters'}}`… The result is: `tool_call=Function(name='calculate_bmi', arguments={'height_m': '1.78', 'weight_kg': '78'})` …where the numbers are converted to strings. They should be **numbers** (floats).
yindo closed this issue 2026-02-15 16:28:38 -05:00
Author
Owner

@ParthSareen commented on GitHub (Jan 2, 2025):

This is a common issue that I've seen occur - especially with smaller models. We are possibly looking to do sampling with grammars to get structured tools back, however for now I'd recommend either using a larger model or adding type safety + retries. So you could do just do float(value) before passing it into the function

@ParthSareen commented on GitHub (Jan 2, 2025): This is a common issue that I've seen occur - especially with smaller models. We are possibly looking to do sampling with grammars to get structured tools back, however for now I'd recommend either using a larger model or adding type safety + retries. So you could do just do `float(value)` before passing it into the function
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#194