Skip to content

fix(gemini): preserve JSON Schema tool parameters - #1259

Open
kolaworld wants to merge 2 commits into
TanStack:mainfrom
kolaworld:fix-1258-gemini-toolcall
Open

fix(gemini): preserve JSON Schema tool parameters#1259
kolaworld wants to merge 2 commits into
TanStack:mainfrom
kolaworld:fix-1258-gemini-toolcall

Conversation

@kolaworld

@kolaworld kolaworld commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #1258

🎯 Changes

  • Sends Gemini tool schemas through FunctionDeclaration.parametersJsonSchema instead of the narrower parameters field.
  • Preserves complete JSON Schema keywords, including nested const values produced by ArkType and other Standard Schema libraries.
  • Uses the @google/genai FunctionDeclaration type, matching the existing Gemini Realtime implementation.
  • Extends the existing provider-dispatch unit coverage and ArkType wire E2E coverage. A model-specific raw mount validates the request without intercepting other Gemini tests.
  • Includes a patch changeset for @tanstack/ai-gemini. Docs are unchanged because public usage and the documented contract remain the same.

Alternatives considered:

  • Patch @copilotkit/aimock. Rejected because the project would need to carry a local dependency patch. The upstream aimock Gemini converter reads only parameters, not parametersJsonSchema. No matching upstream tracker issue is currently filed.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.
  • Docs: I updated docs/ for this change, or this change is not user-facing.
  • Changeset: I added a changeset (pnpm changeset), or this PR does not change a published package.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes

    • Gemini function tools now preserve complete JSON Schema details, including constants and required fields.
    • Updated tool requests to use the current Gemini schema format for improved provider compatibility.
  • Tests

    • Added coverage verifying rich tool schemas are transmitted and accepted by Gemini.
    • Expanded end-to-end validation for Gemini and OpenRouter tool integrations.

@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 8b1b0a4e-34a4-492b-bf58-8a298f3f463d

📥 Commits

Reviewing files that changed from the base of the PR and between 6881d98 and 117f71b.

📒 Files selected for processing (6)
  • .changeset/gemini-json-schema-tools.md
  • packages/ai-gemini/src/tools/tool-converter.ts
  • packages/ai-gemini/tests/provider-tool-dispatch.test.ts
  • testing/e2e/global-setup.ts
  • testing/e2e/src/routes/api.arktype-tool-wire.ts
  • testing/e2e/tests/arktype-tool-wire.spec.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The Gemini tool converter now sends input schemas through parametersJsonSchema. Unit and end-to-end tests verify preservation of JSON Schema keywords such as const.

Changes

Gemini JSON Schema tool support

Layer / File(s) Summary
Update Gemini function declaration schema wiring
packages/ai-gemini/src/tools/tool-converter.ts, packages/ai-gemini/tests/provider-tool-dispatch.test.ts, .changeset/gemini-json-schema-tools.md
The converter uses FunctionDeclaration and assigns schemas to parametersJsonSchema. Unit coverage checks the complete declaration, including unit.const.
Validate Gemini wire format end to end
testing/e2e/src/routes/api.arktype-tool-wire.ts, testing/e2e/global-setup.ts, testing/e2e/tests/arktype-tool-wire.spec.ts
The e2e route selects Gemini when requested. The mock mount validates the raw schema and returns a streamed success response. The e2e test verifies the Gemini request succeeds.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 117f7

The PR preserves complete Gemini tool schemas without changing public usage or introducing merge-blocking correctness, security, or operational risk. It is merge-ready after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant ArkTypeWireTest
  participant ArkTypeToolWireRoute
  participant GeminiTextAdapter
  participant GeminiJsonSchemaToolMount
  ArkTypeWireTest->>ArkTypeToolWireRoute: request provider=gemini
  ArkTypeToolWireRoute->>GeminiTextAdapter: configure Gemini model and test ID
  GeminiTextAdapter->>GeminiJsonSchemaToolMount: send function declaration
  GeminiJsonSchemaToolMount->>GeminiJsonSchemaToolMount: validate parametersJsonSchema
  GeminiJsonSchemaToolMount-->>ArkTypeWireTest: return Schema accepted
Loading

Suggested reviewers: tombeckenham, alemtuzlak

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preserving JSON Schema tool parameters for Gemini.
Description check ✅ Passed The description follows the repository template, explains the change and rationale, records alternatives, completes the checklist, and documents release impact.
Linked Issues check ✅ Passed The changes address issue #1258 by sending complete tool schemas through parametersJsonSchema, preserving keywords such as nested const values, and adding relevant regression coverage.
Out of Scope Changes check ✅ Passed The changeset, converter update, unit tests, wire E2E test, and validation mount directly support the linked issue and stated objectives. No unrelated code changes are identified.
Full details: Docstring Coverage

Explanation

Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nx-cloud

nx-cloud Bot commented Aug 27, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 151e62a

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 1m 57s View ↗
nx run-many --targets=build --exclude=examples/... ✅ Succeeded 9s View ↗

☁️ Nx Cloud last updated this comment at 2026-08-27 21:25:43 UTC

@pkg-pr-new

pkg-pr-new Bot commented Aug 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

@tanstack/ai

npm i https://pkg.pr.new/@tanstack/ai@1259

@tanstack/ai-acp

npm i https://pkg.pr.new/@tanstack/ai-acp@1259

@tanstack/ai-angular

npm i https://pkg.pr.new/@tanstack/ai-angular@1259

@tanstack/ai-anthropic

npm i https://pkg.pr.new/@tanstack/ai-anthropic@1259

@tanstack/ai-bedrock

npm i https://pkg.pr.new/@tanstack/ai-bedrock@1259

@tanstack/ai-byteplus

npm i https://pkg.pr.new/@tanstack/ai-byteplus@1259

@tanstack/ai-claude-code

npm i https://pkg.pr.new/@tanstack/ai-claude-code@1259

@tanstack/ai-client

npm i https://pkg.pr.new/@tanstack/ai-client@1259

@tanstack/ai-code-mode

npm i https://pkg.pr.new/@tanstack/ai-code-mode@1259

@tanstack/ai-code-mode-snippets

npm i https://pkg.pr.new/@tanstack/ai-code-mode-snippets@1259

@tanstack/ai-codex

npm i https://pkg.pr.new/@tanstack/ai-codex@1259

@tanstack/ai-cohere

npm i https://pkg.pr.new/@tanstack/ai-cohere@1259

@tanstack/ai-devtools-core

npm i https://pkg.pr.new/@tanstack/ai-devtools-core@1259

@tanstack/ai-durable-stream

npm i https://pkg.pr.new/@tanstack/ai-durable-stream@1259

@tanstack/ai-elevenlabs

npm i https://pkg.pr.new/@tanstack/ai-elevenlabs@1259

@tanstack/ai-event-client

npm i https://pkg.pr.new/@tanstack/ai-event-client@1259

@tanstack/ai-fal

npm i https://pkg.pr.new/@tanstack/ai-fal@1259

@tanstack/ai-gemini

npm i https://pkg.pr.new/@tanstack/ai-gemini@1259

@tanstack/ai-grok

npm i https://pkg.pr.new/@tanstack/ai-grok@1259

@tanstack/ai-grok-build

npm i https://pkg.pr.new/@tanstack/ai-grok-build@1259

@tanstack/ai-groq

npm i https://pkg.pr.new/@tanstack/ai-groq@1259

@tanstack/ai-isolate-cloudflare

npm i https://pkg.pr.new/@tanstack/ai-isolate-cloudflare@1259

@tanstack/ai-isolate-daytona

npm i https://pkg.pr.new/@tanstack/ai-isolate-daytona@1259

@tanstack/ai-isolate-node

npm i https://pkg.pr.new/@tanstack/ai-isolate-node@1259

@tanstack/ai-isolate-quickjs

npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs@1259

@tanstack/ai-isolate-quickjs-bun

npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs-bun@1259

@tanstack/ai-llmgateway

npm i https://pkg.pr.new/@tanstack/ai-llmgateway@1259

@tanstack/ai-lovable

npm i https://pkg.pr.new/@tanstack/ai-lovable@1259

@tanstack/ai-mcp

npm i https://pkg.pr.new/@tanstack/ai-mcp@1259

@tanstack/ai-memory

npm i https://pkg.pr.new/@tanstack/ai-memory@1259

@tanstack/ai-mistral

npm i https://pkg.pr.new/@tanstack/ai-mistral@1259

@tanstack/ai-octane

npm i https://pkg.pr.new/@tanstack/ai-octane@1259

@tanstack/ai-ollama

npm i https://pkg.pr.new/@tanstack/ai-ollama@1259

@tanstack/ai-openai

npm i https://pkg.pr.new/@tanstack/ai-openai@1259

@tanstack/ai-opencode

npm i https://pkg.pr.new/@tanstack/ai-opencode@1259

@tanstack/ai-openrouter

npm i https://pkg.pr.new/@tanstack/ai-openrouter@1259

@tanstack/ai-perplexity

npm i https://pkg.pr.new/@tanstack/ai-perplexity@1259

@tanstack/ai-persistence

npm i https://pkg.pr.new/@tanstack/ai-persistence@1259

@tanstack/ai-preact

npm i https://pkg.pr.new/@tanstack/ai-preact@1259

@tanstack/ai-react

npm i https://pkg.pr.new/@tanstack/ai-react@1259

@tanstack/ai-react-ui

npm i https://pkg.pr.new/@tanstack/ai-react-ui@1259

@tanstack/ai-sandbox

npm i https://pkg.pr.new/@tanstack/ai-sandbox@1259

@tanstack/ai-sandbox-cloudflare

npm i https://pkg.pr.new/@tanstack/ai-sandbox-cloudflare@1259

@tanstack/ai-sandbox-daytona

npm i https://pkg.pr.new/@tanstack/ai-sandbox-daytona@1259

@tanstack/ai-sandbox-docker

npm i https://pkg.pr.new/@tanstack/ai-sandbox-docker@1259

@tanstack/ai-sandbox-local-process

npm i https://pkg.pr.new/@tanstack/ai-sandbox-local-process@1259

@tanstack/ai-sandbox-sprites

npm i https://pkg.pr.new/@tanstack/ai-sandbox-sprites@1259

@tanstack/ai-sandbox-upstash-box

npm i https://pkg.pr.new/@tanstack/ai-sandbox-upstash-box@1259

@tanstack/ai-sandbox-vercel

npm i https://pkg.pr.new/@tanstack/ai-sandbox-vercel@1259

@tanstack/ai-skills

npm i https://pkg.pr.new/@tanstack/ai-skills@1259

@tanstack/ai-solid

npm i https://pkg.pr.new/@tanstack/ai-solid@1259

@tanstack/ai-solid-ui

npm i https://pkg.pr.new/@tanstack/ai-solid-ui@1259

@tanstack/ai-svelte

npm i https://pkg.pr.new/@tanstack/ai-svelte@1259

@tanstack/ai-utils

npm i https://pkg.pr.new/@tanstack/ai-utils@1259

@tanstack/ai-vercel-gateway

npm i https://pkg.pr.new/@tanstack/ai-vercel-gateway@1259

@tanstack/ai-vertex

npm i https://pkg.pr.new/@tanstack/ai-vertex@1259

@tanstack/ai-vue

npm i https://pkg.pr.new/@tanstack/ai-vue@1259

@tanstack/ai-vue-ui

npm i https://pkg.pr.new/@tanstack/ai-vue-ui@1259

@tanstack/openai-base

npm i https://pkg.pr.new/@tanstack/openai-base@1259

@tanstack/preact-ai-devtools

npm i https://pkg.pr.new/@tanstack/preact-ai-devtools@1259

@tanstack/react-ai-devtools

npm i https://pkg.pr.new/@tanstack/react-ai-devtools@1259

@tanstack/solid-ai-devtools

npm i https://pkg.pr.new/@tanstack/solid-ai-devtools@1259

@tanstack/svelte-ai-devtools

npm i https://pkg.pr.new/@tanstack/svelte-ai-devtools@1259

commit: 151e62a

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.

Gemini tool calls fail with Unknown name "const" because JSON Schema is incorrectly sent as parameters

1 participant