Skip to content

fix: record tool definitions in the semconv function-tool shape and skip unnamed tool calls - #286

Closed
PabloPardoGarcia wants to merge 5 commits into
mainfrom
pablo/rius-1879-semconv-tool-definitions
Closed

PabloPardoGarcia wants to merge 5 commits into
mainfrom
pablo/rius-1879-semconv-tool-definitions

Conversation

@PabloPardoGarcia

@PabloPardoGarcia PabloPardoGarcia commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Two upstream schema changes in the GenAI conventions make part of what we record invalid: semantic-conventions-genai #608 (a type: "function" tool definition must match the function-tool schema) and #584 (a message part with a known type can no longer fall back to the generic part).

Tool definitions

gen_ai.tool.definitions is now written in the conventions' shape, on set_tool_definitions / tools= and on the definitions the normalizer reassembles from OpenInference (llm.tools.N.tool.json_schema) and the request bag (tools / functions). The rules live in rius/_tool_definitions.py:

  • OpenAI's nested {type: "function", function: {...}} is lifted to {type: "function", name, description, parameters, ...}.
  • A definition with a string name and no type (Anthropic custom tools, OpenAI's legacy functions), or Anthropic's explicit type: "custom" with input_schema, becomes a function tool.
  • input_schema / inputSchema is renamed to parameters in place.
  • Bedrock Converse {toolSpec: {name, description, inputSchema: {json: ...}}} is unwrapped to a function tool, inputSchema.json as parameters.
  • A Gemini tool {function_declarations: [...]} / {functionDeclarations: [...]} expands to one function tool per declaration, the schema taken from parameters or else parametersJsonSchema / parameters_json_schema / input_schema / inputSchema. A nameless declaration, and anything else in the Gemini tool (a built-in such as google_search), follows as its own entry, rewritten by the single-tool rules.
  • Any other type is a provider built-in tool. Its fields are kept and its type is prefixed with the provider (gen_ai.provider.name), as #608 recommends: anthropic.web_search_20250305. A type that already contains a dot is left alone, so a second pass never stacks prefixes. No provider, no prefix.
  • A built-in tool without a name (OpenAI web_search_preview, Gemini google_search) gets none invented, on purpose: tool names are read as the tools the model was offered, and an invented name would show up as a tool offered and never called. Such an entry still fails the upstream GenericToolDefinition schema, which requires name.
  • Anything else (not an object, no usable type or name, a Bedrock cachePoint) is kept as it is.

Normalizing twice equals normalizing once. Context sizes are measured from the recorded (normalized) definitions, so tool-definition byte counts change slightly.

Tool calls without a name

The conventions require name on a tool_call part, so omitting the key would still be invalid. A tool call whose name is missing, empty or not a string is now written as a text part holding the call's JSON ({"id", "arguments"}, each left out when absent), the way the SDK already keeps content it has no part type for. Nothing is dropped, and a later tool_call_response still finds its id. This applies on both writers: the generation helper and the OpenInference reassembly (normalization.py). The shared openinference_messages.json fixture has a new case and updated expectations for calls without a name. The sink adopts the same rule in its own change.

Conformance

The shared rius-semconv expected results still hold the provider shapes, so the 12 OpenInference families are listed in tests/conformance/known_differences.json for gen_ai.tool.definitions. Those expected results get regenerated in rius-semconv from this SDK once it is released, and the entries go in that re-sync.

Tests

New tests/test_tool_definitions.py (including Bedrock, Gemini snake/camel case, Gemini built-ins beside declarations, idempotence over all of them); generation, normalization, instrumentation, crash-safety and span-limit tests updated to the new shape. ruff check, ruff format --check, mypy and pytest were green at the first commit; see below for the follow-ups. Outputs checked byte-identical with the TypeScript port on a shared set of inputs, including the Bedrock and Gemini shapes.

Review follow-ups (second commit)

All three implementations (this PR, glassflow/rius-sdk-typescript#251 and glassflow/argus-core#765) take the same changes, and rius-semconv's new shared cases hold them to the same bytes.

  • Idempotence. Every Gemini declarations spelling that holds a list expands (snake case first), and none of them is left in the rest. A declaration's schema is renamed from parametersJsonSchema, parameters_json_schema, input_schema or inputSchema. Nameless declarations and the rest of a Gemini tool now go through the single-tool rule instead of being appended raw. Rewriting any output changes nothing.
  • Nested function. It is lifted only when the tool has no top-level string name, so {"name":"x","function":{...}} keeps its name on every pass.
  • parameters: null counts as no schema: when another spelling holds one, the null goes and that spelling is renamed (a Python model_dump() of a Gemini declaration holds both).
  • type: "" gets no provider prefix, the same as a non-string type.
  • MCP tools. OpenAI Responses' type: "mcp" tool (also once namespaced as openai.mcp) loses its headers member. Those are the requests' headers to the MCP server and can carry an Authorization credential, and credentials never belong in telemetry, content capture or not.
  • Empty list. The sink's rule wins: when the rewritten list is empty ("tools": [], or a Gemini tool with no declarations), the OpenInference and request-bag paths write no gen_ai.tool.definitions, and still remove the sources. set_tool_definitions is unchanged and writes what it is given.
  • pydantic tools. set_tool_definitions records a pydantic model (google-genai's types.Tool) as model_dump(mode="json", exclude_none=True) instead of its repr. A model whose dump raises is kept as given.

Shared cases

sdk_cases/tool_definitions.json is new in glassflow/rius-semconv#117: real provider shapes (OpenAI chat and Responses, Anthropic, Gemini, Bedrock, Vercel AI SDK, MCP) and the edge cases above, with expected results from the Python SDK. Every case asserts that a second pass writes the same bytes as the first. It is vendored here from that PR's head (8db007b) as tests/fixtures/semconv/sdk_cases/tool_definitions.json. After rius-semconv#117 is squash-merged, re-sync it from rius-semconv main (scripts/sync-semconv-fixtures.sh).

Known, not changed here

  • Byte parity holds for canonical JSON. Number text is each language's own (Python writes 1.0, TypeScript 1, the sink keeps the producer's text), and TypeScript orders integer-like keys first. The shared cases hold no float and no integer-like key.
  • A custom mask that redacts parts[].arguments does not see a nameless call's arguments, which sit inside the text part's content string. Worth a line in the masking docs or release notes.

Tests (follow-ups)

New unit tests for each follow-up in tests/test_tool_definitions.py, the empty-list rule on every normalizer route in tests/test_normalization_tools.py, the pydantic model in tests/test_generation.py, and tests/test_sdk_cases.py runs the shared cases (38, once and twice). The shared cases failed 10 of 38 before the fix. ruff check, ruff format --check, mypy and pytest (2985 passed) exit 0.

Review follow-ups (third commit)

In step with glassflow/rius-sdk-typescript#251 and glassflow/argus-core#765; rius-semconv#117 pins each rule with shared cases, re-vendored here from its head 8db007b.

  • MCP authorization. OpenAI's MCP tool also carries authorization, an OAuth access token for the remote server or connector. It is now dropped with headers, for mcp and any provider-prefixed <provider>.mcp type (openai.mcp, azure.mcp). The drop reads the type the tool is written with, so a Vercel provider tool whose id is openai.mcp loses them on the first pass, as it would on the second. Other tools keep an authorization member.
  • Chat Completions custom tools. {"type":"custom","custom":{"name","description","format"}} has its nested members lifted to the top level when the tool has no top-level name (the same rule as function), and stays a non-function tool with the provider-prefixed type: {"type":"openai.custom","name":...,"format":...}, the same shape as the Responses custom tool. Anthropic's type: "custom" with input_schema stays a function tool, and the lifted tool goes through the same rule, so a nested custom holding input_schema is a function tool with or without a provider.
  • Empty names. A name is a non-empty string. {"name":""} (and an empty name on a custom tool with input_schema, a Bedrock toolSpec or a Gemini declaration) no longer becomes a function tool with an empty name; it is kept as given, as an empty-named tool call is not a tool_call part. A nested function is lifted over an empty top-level name.
  • _plain. Only pydantic models from google-genai (a class whose module is google.genai or under it) are dumped. Any other object, such as a LangChain StructuredTool, is recorded as before.

Tests first: new cases in tests/test_tool_definitions.py (MCP authorization on mcp / openai.mcp / azure.mcp and a Vercel MCP tool, other tools keeping authorization, the custom lift and its two neighbours, empty names) and tests/test_generation.py (a non-google-genai pydantic tool is not dumped; the google-genai stand-in now sits under google.genai.types). They failed before the change. tests/test_sdk_cases.py runs the 44 shared cases once and twice. ruff check, ruff format --check, mypy, scripts/sync-semconv.sh --check and pytest (3006 passed, 22 skipped, 1 xfailed) exit 0.

  • MCP credentials in args. The Vercel AI SDK's openai.mcp provider tool (@ai-sdk/openai 4.0.111) holds authorization and headers in its args, beside serverLabel, serverUrl, connectorId, requireApproval and others. For a tool whose final type is mcp / <provider>.mcp, both are now dropped from args too. Other tools' args are untouched. Shared cases re-vendored from rius-semconv#117 8db007b (45). Gate: ruff, mypy, sync check, pytest 3009 passed.

Not in scope, as a follow-up: scrubbing credentials from definitions the rules do not rewrite. A span's native gen_ai.tool.definitions written by another instrumentation, and raw request bodies (OpenInference / OpenLLMetry input.value), keep an MCP tool's headers / authorization. Both are content-gated.

Closes RIUS-1879

…kip unnamed tool calls

A function tool is now recorded as {type: function, name, description,
parameters}: OpenAI's nested function is lifted, Anthropic's input_schema
(and the legacy functions entries) become function tools with parameters.
A provider's built-in tool keeps its fields, with its type prefixed by the
provider name. Applied on set_tool_definitions and on the definitions the
normalizer reassembles from OpenInference and the request bag.

A tool call with no string name is skipped rather than written with
name: null, which the conventions' schema rejects.
@PabloPardoGarcia

Copy link
Copy Markdown
Member Author

Automated review

No blocking issues. The mapping is sound, strict and other provider fields survive, and both SDKs produce the same output. Below are three gaps in what the PR set out to do, plus one cross-component follow-up.

What I checked

  • Upstream text: #608 (FunctionToolDefinition now requires type: "function" + name. GenericToolDefinition excludes function and still requires name. Prefixing with gen_ai.provider.name is RECOMMENDED) and #584.
  • Probed semconv_tool_definitions on 31 real provider inputs: OpenAI chat (with strict), Responses function/web_search_preview/file_search/mcp/freeform custom, legacy functions, Anthropic custom / type: custom / web_search / bash with cache_control, Gemini function_declarations / functionDeclarations / google_search, Bedrock toolSpec, Vercel v4/v5/provider-defined/provider, MCP inputSchema with outputSchema/annotations, plus edge cases. Every case is idempotent (twice == once). The output is byte-identical to the TypeScript port (refactor: drop the userinfo special case from the plain-http warning #251) on all 31.
  • pytest on the branch: 2920 passed. CI is green. Each new known_differences entry has to be there, because the conformance test fails on stale entries.
  • Backend compatibility: argus-core's ToolDefinitionNames (apps/sink/internal/normalize/tooldefnames.go) reads name first, so the amnesia name column keeps working with the new shape.

Good calls

  • Requiring input_schema before treating type: "custom" as a function is right. OpenAI's freeform custom tool ({type: "custom", name, format}) correctly becomes openai.custom and does not turn into a function without a schema.
  • if not native leaves a third party's own gen_ai.tool.definitions untouched. The "already dotted" rule makes prefixing idempotent and lets Vercel's namespaced id pass through.

Should fix

1. Nameless tool_call parts are still written on the OpenInference path. src/rius/normalization.py:762-766 builds {"type": "tool_call"} and adds name only if call.get("function.name"). An OI message whose tool call has no (or an empty) function.name still produces a tool_call part without name, which #584 makes invalid. The skip at src/rius/generation.py:142 covers the native helper only. The ticket's goal is "never write a nameless tool-call part", so apply the same rule here (or say in the PR why this path is out of scope). The sink's OI reassembly mirrors this function, so the rule has to go there too.

2. Skipping drops the call's id and arguments. Consider keeping them. Elsewhere the SDK serializes content it has no part type for into a text part rather than dropping it (see the _content_part docstring at normalization.py:788, "as the generation helper does with content it has no part type for"). Skipping silently loses the arguments, and any later tool_call_response points at an id that no longer exists. A text part holding the serialized call would stay schema-valid and keep the data. That is a judgment call, so please weigh it, but I'd at least keep the behaviour consistent with the existing "serialize, don't drop" convention.

3. Some real shapes are still schema-invalid after normalization (from the probe):

  • Bedrock Converse {"toolSpec": {"name", "description", "inputSchema": {"json": {...}}}} is kept as is: no type, no top-level name. The sink already treats toolSpec.name as a known spelling, so unwrapping to {type: "function", name, description, parameters: inputSchema.json} is cheap.
  • A Gemini Tool container {"function_declarations": [...]} / {"functionDeclarations": [...]}, and built-ins such as {"google_search": {}}, are kept as is. Each declaration could become its own function tool. (Gemini's OpenAPI-style "type": "OBJECT" schemas also won't validate as draft-7 parameters. That is worth knowing, not necessarily worth fixing.)
  • Nameless OpenAI built-ins become {"type": "openai.web_search_preview", ...} with no name, which GenericToolDefinition still rejects because name is required. The docstring's "nothing is invented" is a deliberate choice. Using the bare provider type (web_search_preview) as name is defensible, since it is what the provider calls the tool. Please decide either way and record the decision.

None of these is a regression, because they were invalid before too. If they become follow-ups, the semconv rationale in rius-semconv#114 should not claim "whatever the provider's spelling".

4. The SDK and the sink will diverge until the sink adopts the rule. argus-core apps/sink/internal/normalize/normalize.go:401 reassembles llm.tools.{i}.tool.json_schema verbatim. After this ships, the same OpenInference span gets one shape when the SDK normalized it and another when only the sink did. A tracked sink follow-up would keep the two producers aligned. It would also cover the shared vercel_cases.json mentioned in #251.

Nits

  • Context-size byte counts for tool definitions shift slightly, because sizes are now measured on the normalized JSON. The PR body already says so. Worth a line in the release notes, because dashboards that compare sizes over time will show a small step.

…mini tool definitions

A tool call without a name is written as a text part holding its id and
arguments instead of being dropped, on every path that writes tool_call
parts. Bedrock toolSpec definitions become function tools, and Gemini
function declarations expand to one function tool each.
@PabloPardoGarcia

Copy link
Copy Markdown
Member Author

Addressed in 6e9ad51:

  1. OpenInference path. A tool call left without a name in the OI reassembly is no longer written as a nameless tool_call part.
  2. Skip vs. preserve. Preserve. A call whose name is missing, empty or not a string becomes a text part holding the call's JSON, {"id", "arguments"}, each left out when absent. That follows the existing serialize-don't-drop convention and keeps the id for a later tool_call_response. Same rule on the generation helper and the OI reassembly. The shared openinference_messages.json has a new case and updated expectations.
  3. Shapes. Bedrock toolSpec becomes a function tool (inputSchema.json as parameters). Gemini function_declarations / functionDeclarations expand to one function tool per declaration (parameters, else parametersJsonSchema / parameters_json_schema). Gemini built-ins and nameless OpenAI built-ins stay nameless on purpose: an invented name would show up as a tool offered and never called. Recorded in the module docstring and the PR body. Idempotence covers all of them, and the output stays byte-identical with refactor: drop the userinfo special case from the plain-http warning #251.
  4. Sink parity. The sink port of these rules (text part, Bedrock, Gemini, fixtures) is in progress separately.

Nit (context sizes): noted for the release notes.

ruff, mypy and pytest (2931 passed) are green locally.

@PabloPardoGarcia

Copy link
Copy Markdown
Member Author

Automated review

No blocking issues. The mapping is right for every real provider shape I fed it, and the output is byte-identical to rius-sdk-typescript#251 and argus-core#765. The two known issues (Gemini idempotence, empty list vs. sink) are confirmed below, with a fix, and they are the same in all three PRs. A few smaller edge cases follow.

What I checked

  • Ran the same 31-case corpus through all three implementations (Python semconv_tool_definitions, TS semconvToolDefinitions, Go semconvToolDefinitions via a throwaway test), applying each twice. Inputs: OpenAI chat with strict; Responses function, web_search_preview, file_search, mcp, freeform custom, computer_use_preview; legacy functions; Anthropic custom with cache_control, type: custom, web_search/text_editor/bash/computer; Gemini snake/camel declarations, parametersJsonSchema/parameters_json_schema, google_search/code_execution, nameless declarations; Bedrock toolSpec, cachePoint, systemTool, inputSchema without json; Vercel v4/v5/provider-defined/provider; MCP inputSchema + outputSchema/annotations; and junk (non-objects, type: "", name: "", non-string type/name, __proto__ key, both schema spellings).
  • Every real provider shape is byte-identical across Python, TypeScript and Go and idempotent. Divergences are confined to the cases below.
  • Test suites on the PR heads: Python 2931 passed; TS 2880 passed + tsc --noEmit clean; sink go test ./... green.
  • Earlier automated reviews on fix: record tool definitions in the semconv function-tool shape and skip unnamed tool calls #286/refactor: drop the userinfo special case from the plain-http warning #251: all four points are addressed (OI and Vercel writers covered, preserve-as-text chosen in both SDKs, Bedrock/Gemini converted, sink port is #765). The "nameless built-ins stay nameless" decision is recorded in the docstrings.
  • Text-part rule: under capture_content=False the whole messages attribute is stripped, so the arguments inside the text part go with it. Nothing new leaks.

Idempotence, the general form of the known Gemini issue. The Gemini expansion emits two kinds of entries that never go through the single-tool rule: nameless declarations and the leftover members. When the single-tool rule would rewrite one of them, the second pass changes it. Reproduced identically in all three languages:

input tool once twice
{"function_declarations":[{"name":"a"}],"functionDeclarations":[{"name":"b"}]} [{fn a},{"functionDeclarations":[{"name":"b"}]}] [{fn a},{fn b}]
{"function_declarations":[{"name":"a","input_schema":{..}}]} (also inputSchema) {"type":"function","name":"a","input_schema":{..}} ...,"parameters":{..}
{"function_declarations":[{"type":"web_search"}]} (nameless, typed) {"type":"web_search"} {"type":"gcp.gemini.web_search"}
{"function_declarations":[{"name":"a"}],"name":"x"} (leftover has a name) {"name":"x"} {"type":"function","name":"x"}

Proposed fix, the same in all three. I applied it to a scratch copy of the Python module: the corpus becomes idempotent and tests/test_tool_definitions.py still passes.

  1. Expand every declarations key whose value is a list, snake case first, and leave all expanded keys out of the leftover. A non-list spelling stays in the leftover.
  2. Rename the schema on a declaration with GEMINI_PARAMETER_SPELLINGS + PARAMETER_SPELLINGS, so nothing the second pass's function branch would rename is left behind.
  3. Send nameless declarations and the leftover object back through semconv_tool_definitions([x], provider) instead of appending them raw.

Empty lists, the known sink-vs-SDK issue (wider than Gemini). For the reassembly paths, the SDKs write "[]" and the sink writes nothing. This also happens for a bag with "tools": [] (on main too), not only for {"function_declarations": []}. TS's Vercel branch guards on parsed.length > 0 before shaping, so ai.prompt.tools: ['{"function_declarations":[]}'] writes "[]", while an empty Vercel list writes nothing. Proposed fix: adopt the sink rule in both SDKs. On the three reassembly branches, write gen_ai.tool.definitions only when the shaped list is non-empty, and still delete the sources. The native set_tool_definitions/setToolDefinitions can keep writing whatever it is given, since the sink never rewrites native definitions.

Locations here: src/rius/_tool_definitions.py:76-94 (the expansion and the declaration spellings) and src/rius/normalization.py:637 / :647 (the empty-list guard).

Should fix

  1. Gemini idempotence: the table and fix above (_tool_definitions.py:80, :84, :94).
  2. Empty list: guard both reassembly branches on the shaped list (normalization.py:637, :647).

Suggestions

  1. A name-without-type tool that also has a dict function member is not a fixed point (_tool_definitions.py:101-102). {"name":"x","function":{"name":"y"}} becomes {"type":"function","name":"x","function":{..}} on the first pass. On the second pass the function branch lifts the nested object, and the name becomes y. A declaration with a function member does the same. This is unlikely in practice, but it breaks the invariant. Fix: lift function only when the top level has no string name (OpenAI chat never has one).
  2. parameters: null blocks the rename (_tool_definitions.py:155). "parameters" in tool counts a null member, so a model_dump() of a google-genai FunctionDeclaration (parameters: None, parameters_json_schema: {...}) is recorded with parameters: null and the schema still under parameters_json_schema. The dump's null built-ins also become an extra entry such as {"retrieval":null,"google_search":null,...}. Consider treating a null parameters as absent (drop it, then rename) and dropping a leftover whose members are all null. Mirror both in TS/Go. Related, and pre-existing: a pydantic types.Tool passed to set_tool_definitions is not a dict, so it passes through unshaped and is serialized by repr. The docstring now promises "any provider shape", so either model_dump(exclude_none=True) objects that have it, or narrow the docstring.

Nits

  1. {"type": ""} becomes {"type": "openai."} (_tool_definitions.py:128). Treat an empty type as unusable, the same as a non-string one.
  2. A custom mask that redacts parts[].arguments will not see a nameless call's arguments, which are now inside a text part's content string. Worth a line in the release notes or the masking docs.
  3. Pre-existing, but now visible because the definitions are interpreted: OpenAI Responses {"type":"mcp", "headers": {"Authorization": ...}} is recorded as is. It is content-gated, so it is not a leak under capture_content=False. Still, dropping headers from openai.mcp would be a cheap follow-up.
  4. The tool-definition cases are copied into three test files. A shared testdata/contracts/tool_definitions_cases.json, like openinference_messages.json, with a "twice == once" assertion over every case, would have caught item 1 and would keep the three ports in lockstep. The current idempotence test (tests/test_tool_definitions.py:214) covers only a hand-picked list.
  5. "Byte-identical" holds for canonical JSON only, and that is pre-existing: on the reassembly path Python writes 0.0/1000.0, TS writes 0/1000, and Go keeps the raw 1e3/1.50. TS also moves integer-like keys first. This doesn't need fixing, but the parity claim in the module docstring should say so.

Context-size shift: it is expected and covered by the conformance entries. It goes in the release notes as noted earlier.

Every Gemini declarations spelling that holds a list expands, a declaration's
schema is renamed from any spelling, and nameless declarations and the rest of
a Gemini tool take the single-tool rule, so rewriting an output changes
nothing. A nested function is lifted only without a top-level name, a null
parameters gives way to another schema spelling, and an empty type gets no
prefix. An MCP tool's headers are dropped, since they can carry credentials.
Definitions that come to an empty list write nothing, as the sink does, and
set_tool_definitions records a pydantic tool as its set fields. The shared
rius-semconv tool_definitions cases are vendored and run.
@PabloPardoGarcia

Copy link
Copy Markdown
Member Author

Addressed the review in 9d47941. The same changes went into all three implementations (rius-sdk-python#286, rius-sdk-typescript#251, argus-core#765):

  • Gemini idempotence: every list-valued declarations spelling expands and leaves the rest, a declaration's schema is renamed from the Gemini spellings plus input_schema / inputSchema, and nameless declarations and the rest go through the single-tool rule. All four rows of the table are now fixed points.
  • Empty list: the OpenInference and bag paths write gen_ai.tool.definitions only when the rewritten list is non-empty, and still remove the sources. set_tool_definitions is unchanged.
  • Nested function: lifted only when there is no top-level string name.
  • parameters: null: treated as absent, so the schema rename still happens. set_tool_definitions now records a pydantic model (google-genai types.Tool) as model_dump(mode="json", exclude_none=True) instead of its repr. I didn't drop an all-null leftover. With exclude_none it no longer comes up on the native path.
  • type: "": no prefix.
  • MCP headers: dropped from mcp / openai.mcp tools, since they can carry Authorization credentials.
  • Shared cases: fix: add shared cases for tool definitions in the conventions' shape rius-semconv#117 adds sdk_cases/tool_definitions.json (real provider shapes plus these edge cases, expected from the Python SDK). It is vendored here from that PR's head, and every case asserts twice == once. It needs a re-sync from rius-semconv main after the squash-merge.

Left as known and noted in the PR body: number text and TypeScript's integer-key order outside canonical JSON, and a custom mask not seeing a nameless call's arguments inside the text part.

ruff check, ruff format --check, mypy and pytest (2985 passed) exit 0.

@PabloPardoGarcia

Copy link
Copy Markdown
Member Author

Automated review (follow-up, 9d47941)

No blocking issues. Every should-fix, suggestion and nit from the previous review is fixed, and the TypeScript (#251) and sink (#765) ports were changed in lockstep. One credential field is still missed by the new MCP drop (item 1).

What I checked

  • git diff 6e9ad51c..9d47941. Gemini expansion: every list-valued spelling expands and is excluded from the rest, the declaration schema is renamed from Gemini spellings + input_schema/inputSchema, and nameless declarations and the rest are re-run through the single-tool rule (_tool_definitions.py:96-118). The nested function is lifted only without a top-level string name (:127). A null parameters counts as absent (:185). An empty type is not prefixed (:145). headers is dropped (:147-148). The empty-list guard is normalization.py:649-657 and covers both rebuild branches.
  • Shared cases: tests/test_sdk_cases.py::test_tool_definitions runs all 38 cases from the vendored sdk_cases/tool_definitions.json (identical to rius-semconv#117's head), asserting once == expected and twice == expected. Ran it: 38 passed.
  • Ran an extra 18-case probe through Python, TS and Go. The output was byte-identical and a fixed point everywhere, including non-ASCII/<>& text, escaped keys, type: null with a name, by-alias Gemini dumps with nulls, and Azure MCP.
  • Full suite: pytest 2985 passed, 22 skipped, 1 xfailed. ruff check and mypy src are clean. CI is green (12/12).
  • _plain: the classes guard and the dump-failure fallback are correct. mode="json" renders a SecretStr as **********, so a pydantic tool cannot leak a secret through it that repr would not.

Should fix

  1. authorization on OpenAI's MCP tool is not dropped (_tool_definitions.py:77, :147). openai-python 2.54 Mcp.authorization is an OAuth access token for the remote server or connector. {"type":"mcp","connector_id":"connector_gmail","authorization":"ya29..."} is recorded verbatim as openai.mcp, and capture_content defaults to True. Drop it with headers (same rule in TS/Go, plus a shared case in rius-semconv#117).

Suggestions

  1. The drop covers only the paths that reshape. A native gen_ai.tool.definitions (normalization.py:608, "native wins") from another instrumentation keeps headers/authorization. So does the raw request body in input.value that OpenInference/OpenLLMetry record. Both are content-gated, so this is defence in depth, not a leak under capture_content=False. Consider making the credential drop a scrub that runs on native definitions too (without reshaping them), or say in the docstring that it applies only to definitions the SDK writes.
  2. _plain dumps any pydantic model, not just google-genai's (generation.py:169). A LangChain StructuredTool passed to set_tool_definitions now becomes {"type":"function","name":"add","description":"Add.","args_schema":{...},"return_direct":false,...,"func":"<function add at 0x1078fe770>"}. It claims the function shape, but the schema sits under args_schema and not parameters, and the value carries a per-process address. That is arguably better than the old repr, but it is not the shape the docstring promises. Consider limiting it to google-genai types (type(tool).__module__.startswith("google.genai")) or narrowing the docstring. Also, the new test uses a stand-in model because google-genai is not in the dev environment. A real types.Tool (whose Schema.type dumps as "OBJECT") is not exercised.

Nits

  1. {"name": ""} becomes a function tool with an empty name (pinned by the shared empty_type_and_name), while an empty-named tool call becomes a text part. Confirm that the asymmetry is intended.
  2. Re-sync tests/fixtures/semconv/ from rius-semconv main after feat!: normalize model_parameters keys onto gen_ai.request.* and rius.request.* #117 squash-merges. SOURCE still says ab957f2, but the directory holds feat!: normalize model_parameters keys onto gen_ai.request.* and rius.request.* #117's file. You noted this already.

…reat an empty tool name as none

OpenAI's MCP tool carries authorization, an OAuth access token, beside headers: both go for mcp and any <provider>.mcp type, read from the type the tool is written with so a second pass drops the same members. A Chat Completions custom tool's nested fields are lifted by the function rule and it stays a custom tool. An empty name no longer makes a function tool. Only google-genai's pydantic models are dumped; other pydantic tools are recorded as before. Shared cases re-vendored from rius-semconv#117.
@PabloPardoGarcia

Copy link
Copy Markdown
Member Author

Addressed in bcc1db8:

  1. MCP authorization (should fix): dropped with headers for mcp and any <provider>.mcp type. The drop reads the type the tool is written with, so a Vercel provider tool with id: "openai.mcp" loses them on the first pass as on the second. Other tools keep an authorization member.
  2. Native definitions and raw request bodies (suggestion): not changed here. The module docstring now says the drop applies only to definitions the SDK rewrites, and the PR body lists the scrub as a follow-up.
  3. _plain: now dumps only google-genai's pydantic models (a class whose module is google.genai or under it). Any other object, such as a LangChain StructuredTool, is recorded as before. New test test_set_tool_definitions_does_not_dump_other_pydantic_models; the existing stand-in model now sits under google.genai.types. A real google-genai types.Tool is still not exercised, since google-genai is not a dev dependency.
  4. Empty name: an empty name is now no name, as for tool calls. No function tool is made with an empty name.
  5. Re-sync: still owed after rius-semconv#117 squash-merges.

Also: Chat Completions {"type":"custom","custom":{...}} is lifted as function is and stays openai.custom. Anthropic's custom with input_schema stays a function tool.

Tests were written first and failed before the change. The shared cases are re-vendored from rius-semconv#117 9d238c5 (44 cases, once and twice). ruff check, ruff format --check, mypy, scripts/sync-semconv.sh --check and pytest (3006 passed, 22 skipped, 1 xfailed) exit 0.

The AI SDK's openai.mcp provider tool holds authorization and headers in args. A tool written as mcp or <provider>.mcp now loses them there as well as at the top level. Shared cases re-vendored from rius-semconv#117.
@PabloPardoGarcia

Copy link
Copy Markdown
Member Author

Landed through #289, together with the rius-semconv v1.13.0 sync.

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