Skip to content

Commit 4d7b80a

Browse files
committed
MAP-9 on the complete path: refuse a nameless tool call instead of naming it "tool"
The four parse_response sites (Responses function_call, chat tool_calls[i].function, Anthropic tool_use, Gemini functionCall) raise ProviderError naming the path; unnamed_tool_call_error in providers/common. The stream path had refused since 2026-09-02; the complete path guessed. Six tests; pin moved to the contract commit that adds the four tool_call_unnamed_complete cases. Signed-off-by: Maxime Rivest <mrive052@gmail.com>
1 parent ab56c09 commit 4d7b80a

7 files changed

Lines changed: 79 additions & 7 deletions

File tree

‎CONTRACT_PIN‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8cb228b5688e78035de8160122dabab8045d7e7e
1+
980d037dd0bdd246f6457adf26744fdca12b4072

‎lm15/providers/anthropic.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
batch_entry_request,
7070
default_transport,
7171
)
72-
from .common import EFFORT_THINKING_BUDGETS, MEDIA_KINDS, anthropic_source, check_tool_result_media, iso_utc, model_infos_from_entries, multipart_form_body, parts_to_text
72+
from .common import EFFORT_THINKING_BUDGETS, MEDIA_KINDS, anthropic_source, check_tool_result_media, iso_utc, model_infos_from_entries, multipart_form_body, parts_to_text, unnamed_tool_call_error
7373

7474
# Canonical builtin tool name → Anthropic tool format
7575
_ANTHROPIC_BUILTIN_MAP: dict[str, str] = {
@@ -787,9 +787,11 @@ def parse_response(self, request: Request, response: HttpResponse) -> Response:
787787
if citation is not None:
788788
parts.append(citation)
789789
elif block_type == "tool_use":
790+
if not block.get("name"):
791+
raise unnamed_tool_call_error(self.provider, f"content[{block_index}]")
790792
parts.append(ToolCallPart(
791793
id=str(block.get("id") or f"tool_{len(parts)}"),
792-
name=str(block.get("name") or "tool"),
794+
name=str(block["name"]),
793795
input=block.get("input") if isinstance(block.get("input"), dict) else {},
794796
))
795797
elif block_type == "thinking":

‎lm15/providers/common.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,19 @@ def openai_token_logprobs(entries: Any) -> tuple[TokenLogprob, ...]:
358358
return tuple(out)
359359

360360

361+
def unnamed_tool_call_error(provider: str, path: str) -> "ProviderError":
362+
"""MAP-9 on the complete path (changes/2026-09-07-complete-tool-call-no-guess.md):
363+
a tool call the provider sent without a name is not actionable, and lm15
364+
never guesses which tool the model meant."""
365+
from ..errors import ProviderError
366+
367+
return ProviderError(
368+
f"{provider}: {path} is a tool call with no name; lm15 does not guess "
369+
"which tool the model meant (MAP-9)",
370+
provider=provider,
371+
)
372+
373+
361374
def parse_json_object(value: Any) -> dict[str, Any]:
362375
if isinstance(value, dict):
363376
return value

‎lm15/providers/gemini.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
default_transport,
105105
resolve_credential,
106106
)
107-
from .common import EFFORT_THINKING_BUDGETS, MEDIA_KINDS, build_url, iso_utc, model_infos_from_entries, multipart_related_body, parts_to_text
107+
from .common import EFFORT_THINKING_BUDGETS, MEDIA_KINDS, build_url, iso_utc, model_infos_from_entries, multipart_related_body, parts_to_text, unnamed_tool_call_error
108108

109109
# Canonical builtin tool name → Gemini tool key
110110
_GEMINI_BUILTIN_MAP: dict[str, str] = {
@@ -889,11 +889,13 @@ def _parse_candidate_parts(
889889
data={"value": str(thought_signature)},
890890
),
891891
)
892+
if not fc.get("name"):
893+
raise unnamed_tool_call_error(self.provider, f"{path_prefix}[{part_index}]")
892894
parts.append(ToolCallPart(
893895
# MAP-9: a missing call id is the lm15 correlator tool_call_<index>,
894896
# the same one the stream assembler mints (INV-051 parity).
895897
id=str(fc.get("id") or f"tool_call_{len(parts)}"),
896-
name=str(fc.get("name") or "tool"),
898+
name=str(fc["name"]),
897899
input=fc.get("args") if isinstance(fc.get("args"), dict) else {},
898900
continuation=continuation,
899901
))

‎lm15/providers/openai.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
openai_token_logprobs,
117117
parse_json_object,
118118
part_to_openai_input,
119+
unnamed_tool_call_error,
119120
parts_to_text,
120121
)
121122

@@ -1048,10 +1049,12 @@ def parse_response(self, request: Request, response: HttpResponse) -> Response:
10481049
else:
10491050
_record_unmapped(unmapped, f"output[{item_index}].content[{content_index}]", ctype)
10501051
elif item_type == "function_call":
1052+
if not item.get("name"):
1053+
raise unnamed_tool_call_error(self.provider, f"output[{item_index}]")
10511054
parts.append(
10521055
ToolCallPart(
10531056
id=str(item.get("call_id") or item.get("id") or f"call_{len(parts)}"),
1054-
name=str(item.get("name") or "tool"),
1057+
name=str(item["name"]),
10551058
input=parse_json_object(item.get("arguments")),
10561059
)
10571060
)

‎lm15/providers/openai_chat.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
model_infos_from_entries,
5858
openai_token_logprobs,
5959
parse_json_object,
60+
unnamed_tool_call_error,
6061
parts_to_text,
6162
)
6263
from .openai import (
@@ -682,10 +683,12 @@ def parse_response(self, request: Request, response: HttpResponse) -> Response:
682683
_record_unmapped(unmapped, f"choices[0].message.tool_calls[{call_index}]", call_type)
683684
continue
684685
function = call.get("function") if isinstance(call.get("function"), dict) else {}
686+
if not function.get("name"):
687+
raise unnamed_tool_call_error(self.provider, f"choices[0].message.tool_calls[{call_index}]")
685688
parts.append(
686689
ToolCallPart(
687690
id=str(call.get("id") or f"call_{len(parts)}"),
688-
name=str(function.get("name") or "tool"),
691+
name=str(function["name"]),
689692
input=parse_json_object(function.get("arguments")),
690693
)
691694
)

‎tests/test_map9_complete_path.py‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""MAP-9 on the complete path (changes/2026-09-07-complete-tool-call-no-guess.md):
2+
a non-streaming reply whose tool call has no name is refused with
3+
ProviderError; lm15 never substitutes a name."""
4+
5+
import json
6+
7+
import pytest
8+
9+
from lm15 import Message, ProviderError, Request
10+
from lm15.providers.base import HttpResponse
11+
from lm15.vet import adapter_for_provider
12+
13+
14+
def _lm(provider: str):
15+
return adapter_for_provider(provider, "test-key")
16+
17+
18+
def _http(body: dict) -> HttpResponse:
19+
return HttpResponse(status=200, reason="OK", headers=[], body=json.dumps(body).encode())
20+
21+
22+
REQUEST = Request(model="m", messages=[Message.user("hi")])
23+
24+
BODIES = {
25+
"openai": {"output": [{"type": "function_call", "call_id": "c", "arguments": "{}"}]},
26+
"openai_chat": {"choices": [{"message": {"tool_calls": [{"id": "c", "function": {"arguments": "{}"}}]}}]},
27+
"anthropic": {"content": [{"type": "tool_use", "id": "t", "input": {}}]},
28+
"gemini": {"candidates": [{"content": {"parts": [{"functionCall": {"args": {}}}]}}]},
29+
}
30+
31+
32+
@pytest.mark.parametrize("provider", sorted(BODIES))
33+
def test_nameless_tool_call_is_refused(provider: str) -> None:
34+
with pytest.raises(ProviderError) as info:
35+
_lm(provider).parse_response(REQUEST, _http(BODIES[provider]))
36+
assert info.value.code == "provider"
37+
assert "no name" in str(info.value)
38+
39+
40+
def test_empty_name_is_no_name() -> None:
41+
body = {"content": [{"type": "tool_use", "id": "t", "name": "", "input": {}}]}
42+
with pytest.raises(ProviderError):
43+
_lm("anthropic").parse_response(REQUEST, _http(body))
44+
45+
46+
def test_named_calls_still_parse() -> None:
47+
body = {"content": [{"type": "tool_use", "id": "t", "name": "get_weather", "input": {"city": "x"}}]}
48+
response = _lm("anthropic").parse_response(REQUEST, _http(body))
49+
assert response.tool_calls[0].name == "get_weather"

0 commit comments

Comments
 (0)