diff --git a/src/inference_endpoint/evaluation/bfcl_v4_execution.py b/src/inference_endpoint/evaluation/bfcl_v4_execution.py index e6b51293c..d7d57e228 100644 --- a/src/inference_endpoint/evaluation/bfcl_v4_execution.py +++ b/src/inference_endpoint/evaluation/bfcl_v4_execution.py @@ -231,7 +231,7 @@ def process_response( model_responses_bfcl = [] for tc in tool_calls: name = tc["name"] - if allowed_names and name not in allowed_names: + if name not in allowed_names: logger.warning( "Dropping tool call to undeclared function %r for %s turn " "%d (not in the entry's tool list); refusing to execute an " diff --git a/tests/unit/evaluation/test_bfcl_v4_execution.py b/tests/unit/evaluation/test_bfcl_v4_execution.py index 86856adc3..b0bbf0941 100644 --- a/tests/unit/evaluation/test_bfcl_v4_execution.py +++ b/tests/unit/evaluation/test_bfcl_v4_execution.py @@ -40,7 +40,7 @@ def _state(entry_id="multi_turn_base_0", max_steps=25): current_step=0, current_turn_results=[], messages=[], - tools=[], + tools=[{"type": "function", "function": {"name": "f"}}], force_terminated=False, completed=False, model_results_per_turn=[], @@ -112,14 +112,18 @@ def test_process_response_no_tool_calls_advances_turn(): @pytest.mark.unit -def test_process_response_drops_undeclared_tool_name(): +@pytest.mark.parametrize( + "tools", + [[{"type": "function", "function": {"name": "f"}}], [], [{"type": "function"}]], +) +def test_process_response_drops_undeclared_tool_name(tools): """A tool call to a name the entry never declared must not reach bfcl-eval's executor (guards against injection like __import__('os').system).""" executed = [] bridge = _make_bridge() state = _state() state.entry.num_turns = 1 - state.tools = [{"type": "function", "function": {"name": "f"}}] + state.tools = tools with ( patch.object(ex, "convert_to_function_call", lambda calls: list(calls)), patch.object(ex, "is_empty_execute_response", lambda d: len(d) == 0),