Skip to content

fix: harden tool invocation and function-call validation#49

Open
Ridwannurudeen wants to merge 1 commit intoNousResearch:mainfrom
Ridwannurudeen:fix/tool-runtime-validation-hardening
Open

fix: harden tool invocation and function-call validation#49
Ridwannurudeen wants to merge 1 commit intoNousResearch:mainfrom
Ridwannurudeen:fix/tool-runtime-validation-hardening

Conversation

@Ridwannurudeen
Copy link

Summary

This PR fixes two runtime correctness issues in the recursive tool-calling loop and adds regression tests.

Problems Fixed

  1. Tool execution used positional dispatch via *function_args.values(), which is order-dependent and can misroute arguments for multi-parameter tools.
  2. Function-call schema validation skipped type checks for falsey argument values (0, False, "", None), allowing invalid calls through.
  3. Integer/number checks relied on Python isinstance, which incorrectly treats booleans as integers.

Changes

  • Added tool_runtime.py:
    • invoke_tool(...) for deterministic invocation:
      • uses .invoke(dict_args) when available (LangChain tool objects)
      • otherwise uses callable(**dict_args)
    • format_tool_result(...) for JSON-safe <tool_response> payloads.
  • Updated functioncall.py to route execution/serialization through the new runtime helper.
  • Hardened validator.py:
    • always validates provided args, including falsey values
    • enforces JSON-schema-consistent numeric typing (bool is rejected for integer/number)
    • added explicit error for unsupported schema types.

Tests

Added focused regression coverage:

  • tests/test_tool_runtime.py
  • tests/test_validator.py

Local run:

python -m pytest -q tests
# 9 passed

Why this matters

These are correctness fixes in the core tool-use path, reducing silent argument corruption and invalid tool-call acceptance during multi-turn function-calling loops.

@Ridwannurudeen
Copy link
Author

Maintainer note: this fixes argument misrouting in tool invocation plus falsey-value validation bugs, with 9 focused regression tests to lock behavior.

@Ridwannurudeen
Copy link
Author

@interstellarninja @teknium1 when you have a moment, could you take a look at this fix? It targets core tool-use correctness and includes regression tests.

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.

1 participant