From 288137a4f79502f71bcc576042aee4e44163a9ba Mon Sep 17 00:00:00 2001 From: Pablo Pardo Garcia Date: Tue, 17 Nov 2026 10:00:59 +0100 Subject: [PATCH 1/2] test: cover an orphan tool description and the copy drop under native definitions Two cases for the llm.tools name and description drop: a description at an index with no schema stays, and the copies still go when a native gen_ai.tool.definitions is already on the span. --- tests/test_normalization_tools.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_normalization_tools.py b/tests/test_normalization_tools.py index f45f565..2332efa 100644 --- a/tests/test_normalization_tools.py +++ b/tests/test_normalization_tools.py @@ -218,6 +218,25 @@ def test_a_name_without_a_schema_is_not_touched() -> None: assert out["llm.tools.1.tool.name"] == "b" +def test_a_description_without_a_schema_is_not_touched() -> None: + attributes = {**_indexed([{"name": "a"}]), "llm.tools.1.tool.description": "orphan"} + out = normalize_tool_definitions(attributes) + assert out is not None + assert out["llm.tools.1.tool.description"] == "orphan" + + +def test_a_native_definitions_key_wins_and_the_name_and_description_still_go() -> None: + attributes = { + GEN_AI_TOOL_DEFINITIONS: '[{"name": "native"}]', + **_indexed(_ANTHROPIC_TOOLS), + "llm.tools.0.tool.name": "get_weather", + "llm.tools.0.tool.description": "Weather for a city", + } + assert normalize_tool_definitions(attributes) == { + GEN_AI_TOOL_DEFINITIONS: '[{"name": "native"}]' + } + + def test_an_unparseable_schema_leaves_the_name_and_description_too() -> None: attributes = { "llm.tools.0.tool.json_schema": "{not json", From 0db440350bed41d3f79d73460ad44653324d5cd7 Mon Sep 17 00:00:00 2001 From: Pablo Pardo Garcia Date: Tue, 17 Nov 2026 10:04:26 +0100 Subject: [PATCH 2/2] fix: drop a tool's name and description copies only when spelled like its schema key The copy key is now the schema key as written with .tool.json_schema stripped, as the sink does, rather than rebuilt from the parsed index. llm.tools.01.tool.json_schema takes llm.tools.01.tool.name with it and leaves llm.tools.1.tool.name alone. --- src/rius/normalization.py | 7 +++++-- tests/test_normalization_tools.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/rius/normalization.py b/src/rius/normalization.py index a1da18c..e31a809 100644 --- a/src/rius/normalization.py +++ b/src/rius/normalization.py @@ -579,6 +579,7 @@ def error_type_from_exception_event(span: ReadableSpan) -> dict[str, Any]: #: their own beside its schema, as ``llm.tools.{i}.tool.``. Copies of #: the schema's own fields, so they go wherever the schema goes. _LLM_TOOL_SCHEMA_COPIES = ("name", "description") +_LLM_TOOL_SCHEMA_SUFFIX = ".tool.json_schema" def normalize_tool_definitions(attributes: Mapping[str, Any] | None) -> dict[str, Any] | None: @@ -641,9 +642,11 @@ def normalize_tool_definitions(attributes: Mapping[str, Any] | None) -> dict[str return None schemas.append(schema) drop = set(indexed.values()) + # Each copy is spelled from its schema key as written, so a copy + # goes only when its index is spelled exactly like its schema's. drop.update( - f"llm.tools.{index}.tool.{member}" - for index in indexed + f"{key.removesuffix(_LLM_TOOL_SCHEMA_SUFFIX)}.tool.{member}" + for key in indexed.values() for member in _LLM_TOOL_SCHEMA_COPIES ) rebuilt = {k: v for k, v in attributes.items() if k not in drop} diff --git a/tests/test_normalization_tools.py b/tests/test_normalization_tools.py index 2332efa..c1208b3 100644 --- a/tests/test_normalization_tools.py +++ b/tests/test_normalization_tools.py @@ -237,6 +237,21 @@ def test_a_native_definitions_key_wins_and_the_name_and_description_still_go() - } +def test_a_copy_goes_only_when_spelled_like_its_schema_key() -> None: + # The copy key is the schema key as written, so a zero-padded index + # takes its own padded copy and leaves the unpadded one alone. + attributes = { + "llm.tools.01.tool.json_schema": json.dumps({"name": "a"}), + "llm.tools.1.tool.name": "kept", + "llm.tools.01.tool.name": "a", + } + out = normalize_tool_definitions(attributes) + assert out is not None + assert _definitions(out) == [{"type": "function", "name": "a"}] + assert out["llm.tools.1.tool.name"] == "kept" + assert "llm.tools.01.tool.name" not in out + + def test_an_unparseable_schema_leaves_the_name_and_description_too() -> None: attributes = { "llm.tools.0.tool.json_schema": "{not json",