Skip to content

fix(ai-gemini): remove redundant text part from functionResponse messages#448

Merged
AlemTuzlak merged 2 commits intomainfrom
pr-436
Apr 14, 2026
Merged

fix(ai-gemini): remove redundant text part from functionResponse messages#448
AlemTuzlak merged 2 commits intomainfrom
pr-436

Conversation

@jherr
Copy link
Copy Markdown
Contributor

@jherr jherr commented Apr 13, 2026

Summary

  • Fixes @tanstack/ai-gemini Error 400 when sending a functionResponse #436 — tool result messages were emitting both a { text } part and a { functionResponse } part in the same Gemini API message
  • Newer models (gemini-3.1-flash-lite, gemma-4) reject this combination with a 400 error
  • The fix skips emitting the redundant text part for role: "tool" messages since the content is already in the functionResponse

Test plan

  • Updated existing tests to assert tool-result text parts are no longer emitted
  • All 65 ai-gemini tests pass
  • Full test suite (29 projects) passes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Resolved a 400 error when sending tool results to newer Gemini models by changing how tool response messages are formatted. Tool-result content is no longer included as redundant text parts, preventing API rejections and improving reliability when delivering tool outputs to Gemini.

…ages (#436)

Tool result messages were emitting both a text part and a functionResponse
part, causing 400 errors on newer Gemini models that reject mixed parts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4691cbaf-aa67-42a4-8dd4-87738ffb8082

📥 Commits

Reviewing files that changed from the base of the PR and between 16609f7 and c2ce593.

📒 Files selected for processing (1)
  • packages/typescript/ai-gemini/tests/gemini-adapter.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/typescript/ai-gemini/tests/gemini-adapter.test.ts

📝 Walkthrough

Walkthrough

This PR removes redundant text parts from Gemini functionResponse messages, updating the adapter to avoid including text content for tool-role messages to prevent Gemini API 400 errors.

Changes

Cohort / File(s) Summary
Changeset Documentation
/.changeset/fix-gemini-function-response.md
Adds a changeset for a patch release to document the fix removing redundant text parts from functionResponse messages for @tanstack/ai-gemini.
Adapter Logic
packages/typescript/ai-gemini/src/adapters/text.ts
Adjusts GeminiTextAdapter.formatMessages so text-only message content is not converted into a text part when msg.role === 'tool'; text conversion now occurs only when msg.role !== 'tool'.
Tests
packages/typescript/ai-gemini/tests/gemini-adapter.test.ts
Updates test assertions to expect functionResponse parts without redundant tool-result text parts and to assert the presence of only the follow-up text where applicable.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I nibbled code in moonlight's gleam,
Removed the duplicate text from the stream.
Now Gemini nods, no 400 cry—
One clear part, and spirits fly. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description provides the motivation (issue #436), explains the fix, test coverage, and acknowledges generation with Claude Code; however, it doesn't follow the provided template structure. Consider restructuring the description to explicitly follow the template with '## 🎯 Changes' section, checklist items, and '## 🚀 Release Impact' section for consistency.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: removing redundant text parts from Gemini functionResponse messages.
Linked Issues check ✅ Passed The PR fully addresses issue #436 by preventing duplicate text and functionResponse parts in tool result messages, ensuring Gemini API compliance without 400 errors.
Out of Scope Changes check ✅ Passed All changes directly address the issue: removing redundant text parts from functionResponse messages. The changeset, code fix, and test updates are all scope-aligned.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pr-436

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 and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

🚀 Changeset Version Preview

1 package(s) bumped directly, 3 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/ai-gemini 0.8.6 → 0.8.7 Changeset
@tanstack/ai-code-mode-models-eval 0.0.4 → 0.0.5 Dependent
ts-svelte-chat 0.1.30 → 0.1.31 Dependent
ts-vue-chat 0.1.30 → 0.1.31 Dependent

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 13, 2026

View your CI Pipeline Execution ↗ for commit c2ce593

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

☁️ Nx Cloud last updated this comment at 2026-04-13 17:48:30 UTC

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 13, 2026

Open in StackBlitz

@tanstack/ai

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

@tanstack/ai-anthropic

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

@tanstack/ai-client

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

@tanstack/ai-code-mode

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

@tanstack/ai-code-mode-skills

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

@tanstack/ai-devtools-core

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

@tanstack/ai-elevenlabs

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

@tanstack/ai-event-client

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

@tanstack/ai-fal

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

@tanstack/ai-gemini

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

@tanstack/ai-grok

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

@tanstack/ai-groq

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

@tanstack/ai-isolate-cloudflare

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

@tanstack/ai-isolate-node

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

@tanstack/ai-isolate-quickjs

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

@tanstack/ai-ollama

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

@tanstack/ai-openai

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

@tanstack/ai-openrouter

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

@tanstack/ai-preact

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

@tanstack/ai-react

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

@tanstack/ai-react-ui

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

@tanstack/ai-solid

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

@tanstack/ai-solid-ui

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

@tanstack/ai-svelte

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

@tanstack/ai-vue

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

@tanstack/ai-vue-ui

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

@tanstack/preact-ai-devtools

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

@tanstack/react-ai-devtools

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

@tanstack/solid-ai-devtools

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

commit: c2ce593

@AlemTuzlak AlemTuzlak merged commit 4990150 into main Apr 14, 2026
8 checks passed
@AlemTuzlak AlemTuzlak deleted the pr-436 branch April 14, 2026 09:07
@github-actions github-actions bot mentioned this pull request Apr 14, 2026
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.

@tanstack/ai-gemini Error 400 when sending a functionResponse

2 participants