Skip to content

fix(providers): preserve tool input schemas for Anthropic and Google - #76

Draft
ibetitsmike wants to merge 2 commits into
coder_2_33from
mike/tool-input-schema-passthrough
Draft

ibetitsmike wants to merge 2 commits into
coder_2_33from
mike/tool-input-schema-passthrough

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Oct 27, 2026 •

Copy link
Copy Markdown

Anthropic, Bedrock and native Google rebuilt every tool input schema from properties and required only. Schemas from MCP servers that use $defs and $ref reached the model with references that point at nothing. Google also turned every property without a type, including each $ref, into a string argument.

Changes

  • Anthropic and Bedrock: toTools forwards every top-level schema keyword except type, properties and required through ToolInputSchemaParam.ExtraFields. Examples are $defs, additionalProperties and the root description. required is now also accepted as []any, which is what JSON decoding produces.
  • Google: toGoogleTools sends each tool schema unchanged as FunctionDeclaration.parametersJsonSchema instead of converting it into the OpenAPI-style parameters field. The old converter is removed. A tool with a nil schema sends neither field, so it declares no parameters.
    • Google documents native JSON Schema support for parametersJsonSchema on both the Gemini API and Vertex AI, including $ref, $defs, anyOf and additionalProperties. fantasy already uses the matching responseJsonSchema field for object generation.
    • genai.Schema cannot express references, numeric enums or untyped object roots. A converter must either drop those or inline references, and inlining expands exponentially on schemas that reference one definition more than once.
  • Recorded Google requests: the 26 providertests cassettes with tool declarations now record parametersJsonSchema in place of parameters. The only other change is the request content_length. The schemas are the same objects with lowercase JSON Schema types.

This replaces #53, which targeted main.

Validation

  • go test ./... passes, including all 82 Google providertests cases that replay the recorded requests.
  • golangci-lint run --allow-parallel-runners ./... reports no issues in the changed files. The 3 existing prealloc findings are in agent.go and providers/kronk.
  • TestToolInputSchemaReachesRequest checks the request body for both the Gemini API and Vertex backends. Its schema has an untyped root, a $ref with sibling keywords, a recursive definition, a numeric enum and a null branch behind a $ref. It fails with the base google.go ($ref becomes STRING) and with this PR's first commit (the untyped root becomes {"type":"STRING"}).
  • TestToTools_PreservesFunctionInputSchema fails with the base anthropic.go.
  • I sent a live Anthropic request (claude-haiku-4-5) through the Coder AI Gateway with an input_schema that carries $defs, a $ref property, additionalProperties: false and a root description. It returned 200 and the tool call {"filter":{"term":"coder"}}.
  • I could not send a live native Gemini request: the gateway has no native route and the local key is rejected.

coder/coder consumes this in the MCP tool schema stack (coder/coder#28376).

🤖 Xum opened this PR on behalf of @ibetitsmike.

Anthropic (and Bedrock, which delegates to it) rebuilt input_schema from
properties and required only, and dropped required when it was []any.
Forward every other schema keyword through ExtraFields and accept both
required shapes.

Google converted only root properties into genai.Schema and turned any
property without a type, including every $ref, into a string. Inline
local references (any JSON Pointer, percent-decoded), convert enum,
anyOf, nested required, and nullable alternatives, and drop recursive or
unresolvable references together with their required entries instead
of degrading them to strings.
@ibetitsmike

ibetitsmike commented Oct 27, 2026 •

Copy link
Copy Markdown
Author

@codex review

🤖 Xum posted this comment for @ibetitsmike.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T03:29:12.583625Z 4c2c213 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b19528eeea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread providers/google/google.go Outdated
Comment thread providers/google/google.go Outdated
Comment thread providers/google/google.go Outdated
Comment thread providers/google/google.go Outdated
Comment thread providers/google/google.go Outdated
Comment thread providers/google/google.go Outdated
The Gemini API and Vertex AI accept JSON Schema directly through
FunctionDeclaration.parametersJsonSchema. Send each tool schema there
unchanged instead of converting it into the OpenAPI-style parameters
field, which cannot express references, numeric enums, or untyped
object roots and lost or corrupted tool arguments when converted.

Remove the hand-written schema converter and update the recorded
Google requests to the new declaration shape.
@ibetitsmike

ibetitsmike commented Oct 27, 2026 •

Copy link
Copy Markdown
Author

@codex review

🤖 Xum posted this comment for @ibetitsmike.

@ibetitsmike

Copy link
Copy Markdown
Author

@codex review

🤖 Xum posted this comment for @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 4c2c213d76

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant