Skip to content

fix: add shared cases for tool definitions in the conventions' shape - #117

Merged
PabloPardoGarcia merged 3 commits into
mainfrom
pablo/rius-1879-tool-definitions-cases
Nov 16, 2026
Merged

PabloPardoGarcia merged 3 commits into
mainfrom
pablo/rius-1879-tool-definitions-cases

Conversation

@PabloPardoGarcia

@PabloPardoGarcia PabloPardoGarcia commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Adds sdk_cases/tool_definitions.json: one shared set of cases for the rules that rewrite gen_ai.tool.definitions into the conventions' shape. The Python SDK, the TypeScript SDK and the sink each implement those rules, and until now each copied the cases into its own tests.

Each case gives tools in a provider's own shape, the span's provider, and expected, the rewritten list's compact JSON (key order included). Every implementation must write expected, and rewriting its own output must write expected again. That second check is the one that keeps the three ports from drifting into a shape the sink would rewrite a second time.

Coverage:

  • Real provider shapes: OpenAI chat (with strict) and chat custom, Responses function, built-ins, freeform custom and mcp; legacy functions; Anthropic custom (with cache_control), type: custom, server tools; Gemini snake and camel declarations, parametersJsonSchema / parameters_json_schema, built-ins beside declarations; Bedrock toolSpec, cachePoint, systemTool, inputSchema without json; Vercel AI SDK function and provider tools; MCP tools with inputSchema / outputSchema / annotations.
  • Edge cases: both Gemini declaration spellings in one tool, a declaration schema spelled input_schema / inputSchema, nameless declarations and the rest of a Gemini tool going through the single-tool rule, a nested function beside a top-level name, parameters: null (a Python model_dump() of a Gemini declaration), type: "", an MCP tool's headers and authorization (dropped, for mcp and any <provider>.mcp type, since they carry credentials), Chat Completions custom tools (nested members lifted, still a custom tool) beside Anthropic's custom with input_schema (a function tool), an empty name (no name, so no function tool), non-object and non-string junk, a __proto__ key, and the empty list.

The expected results come from the Python SDK. The cases hold no float and no integer-like key, whose text differs by language.

sdk_cases/README.md lists the file and notes that the sink vendors it as well. tests/test_sdk_cases.py checks that the file is well formed and that expected is compact JSON.

Consumers (each vendors this file from this branch for now, and must re-sync from main after this is squash-merged):

Review follow-ups

Six new cases (44 in all), with expected from the Python SDK at glassflow/rius-sdk-python#286 bcc1db8, each a fixed point:

  • openai_responses_mcp_authorization_dropped: an MCP connector tool with authorization, and one with both authorization and headers.
  • mcp_credentials_dropped_for_any_provider_prefix: azure.mcp, a Vercel provider tool with id: "openai.mcp", and a non-MCP tool that keeps its authorization.
  • openai_chat_custom_lifted, custom_nested_not_lifted_over_a_name, custom_lifted_with_input_schema_is_a_function: the Chat Completions custom shape, pinned apart from Anthropic's custom (anthropic_explicit_custom_type).
  • empty_name_is_no_name: an empty name on a bare tool, a custom tool with input_schema, a Bedrock toolSpec and a Gemini declaration, and a nested function lifted over an empty top-level name.

empty_type_and_name now expects {"name":""} kept as given, not a function tool with an empty name. about and sdk_cases/README.md say so. The file is vendored byte-identically (sha1 f3374f7a) into all three consumers. pytest (1167 passed) and the tools/check_*.py checks exit 0.

  • New case vercel_mcp_provider_tool_args_credentials_dropped (45 in all): provider and provider-defined openai.mcp tools lose authorization / headers from args, and an openai.web_search tool keeps an authorization in its args. Vendored byte-identically (sha1 a41a876f).

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.

Every implementation of the tool-definition rules (both SDKs and the sink)
runs these cases and asserts that rewriting its own output changes nothing.
@PabloPardoGarcia

Copy link
Copy Markdown
Member Author

Automated review

No blocking issues. The 38 cases are real provider shapes plus the edge cases from the last review round. Every expected matches the conventions' tool-definition shape ({"type":"function","name","description"?,"parameters"?} for function tools, a provider-prefixed type for built-ins) and the deliberate choices: nameless built-ins stay nameless, a dotted type is not prefixed again, MCP headers are dropped, unreadable entries are kept. One case should be added before merge (item 1).

What I checked

  • Read all 38 cases against the rules. All four idempotence rows from the previous review are pinned (gemini_both_declaration_spellings, gemini_declaration_with_input_schema, gemini_nameless_typed_declaration, gemini_rest_with_a_name). So are the nested-function rule, null parameters, empty type and the headers drop.
  • The file is byte-identical (sha1 255e9f88) to the copies vendored in rius-sdk-python#286, rius-sdk-typescript#251 and argus-core#765. Each repo runs all 38 cases, asserting once == expected and twice == expected: Python 38 passed, TS 38 passed, Go 38 subtests passed.
  • tests/test_sdk_cases.py passes locally (19 passed), and CI is green.
  • I also ran an 18-case probe corpus through all three implementations: Azure MCP, Chat Completions custom, google-genai by_alias dumps with nulls, type: null with a name, non-ASCII and <>& text, escaped keys and empty-provider strings. The output was byte-identical and a fixed point in all three. The text format is therefore stable beyond the shared file, apart from floats and integer-like keys, which are already excluded.

Should fix

  1. OpenAI's MCP tool has a second credential field, authorization. In openai-python 2.54 responses/tool_param.py, Mcp.authorization is "An OAuth access token that can be used with a remote MCP server, either with a custom MCP server URL or a service connector". {"type":"mcp","server_label":"gh","connector_id":"connector_gmail","authorization":"ya29..."} currently comes out as openai.mcp with the token intact in all three implementations. capture_content defaults to True, so this is exported by default. Please extend openai_responses_mcp_headers_dropped (sdk_cases/tool_definitions.json:94), or add a sibling case, so authorization is dropped too. The implementations change in the three consumer PRs.

Suggestions

  1. Chat Completions custom tools nest their fields. The Chat Completions shape is {"type":"custom","custom":{"name","description","format"}}, and today it becomes {"type":"openai.custom","custom":{...}}, with the name hidden inside. That differs from the Responses shape pinned in openai_responses_custom_freeform (:79), where name is top level. Lifting custom (as function is lifted) and keeping it nested are both defensible. Either way, add a case so the choice is pinned in all three.

Nits

  1. empty_type_and_name (:726) pins {"name":""} → {"type":"function","name":""}. That is a function tool with an empty name. For tool calls, the same PRs treat an empty name as missing (the call becomes a text part). If that asymmetry is intended, a sentence in about would help, because three repos now pin it.
  2. about says the expectations come from the Python SDK. That is fine. Once this merges, all three consumers need the re-sync from main (their SOURCE files still say ab957f2 while holding this PR's file).

…pty tool names

OpenAI's MCP tool also carries authorization, an OAuth access token: it goes with headers for mcp and any <provider>.mcp type. A Chat Completions custom tool nests its fields under custom; they are lifted as function's are and the tool stays a custom tool, unless the lifted tool is Anthropic's custom tool with an input_schema. An empty name is no name, as for tool calls.
@PabloPardoGarcia

Copy link
Copy Markdown
Member Author

Addressed in 9d238c5:

  1. MCP authorization (should fix): new cases openai_responses_mcp_authorization_dropped (a connector tool with authorization, and one with authorization plus headers) and mcp_credentials_dropped_for_any_provider_prefix (azure.mcp, a Vercel provider tool with id: "openai.mcp", and a non-MCP tool that keeps its authorization). All three implementations drop headers and authorization for mcp and any <provider>.mcp type.
  2. Chat Completions custom: lifted, as function is. openai_chat_custom_lifted pins {"type":"custom","custom":{...}} → {"type":"openai.custom","name",...}, the same shape as openai_responses_custom_freeform. custom_nested_not_lifted_over_a_name and custom_lifted_with_input_schema_is_a_function keep it apart from Anthropic's custom with input_schema (still a function tool).
  3. Empty name: no longer an asymmetry. A name is a non-empty string, as for tool calls. empty_type_and_name now expects {"name":""} kept as given, and empty_name_is_no_name covers a bare tool, a custom with input_schema, a Bedrock toolSpec, a Gemini declaration, and a nested function lifted over an empty top-level name. about and the README say so.
  4. Re-sync: still owed after the squash-merge; noted in each consumer PR.

44 cases, expectations from the Python SDK (rius-sdk-python#286 bcc1db8), each a fixed point. Vendored byte-identically (sha1 f3374f7a) into rius-sdk-python#286, rius-sdk-typescript#251 and argus-core#765. pytest (1167 passed) and the tools/check_*.py checks exit 0.

Follow-up, not in this PR: scrubbing credentials from native gen_ai.tool.definitions written by third-party instrumentations and from raw request bodies.

The AI SDK's openai.mcp provider tool holds authorization and headers in args; a tool written as mcp or <provider>.mcp loses them there too.
@PabloPardoGarcia
PabloPardoGarcia merged commit b14779a into main Nov 16, 2026
6 checks passed
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