Skip to content

fix(gemini): drop sampling parameters and candidate_count for Gemini 3 models - #863

Merged
SantiagoDePolonia merged 1 commit into
mainfrom
fix/gemini-3-sampling-params
Sep 2, 2026
Merged

fix(gemini): drop sampling parameters and candidate_count for Gemini 3 models#863
SantiagoDePolonia merged 1 commit into
mainfrom
fix/gemini-3-sampling-params

Conversation

@SantiagoDePolonia

@SantiagoDePolonia SantiagoDePolonia commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Google's Gemini 3 migration guides say to remove temperature, top_p and top_k from every request ("Gemini 3's reasoning capabilities are optimized for the default settings", "Remove these parameters from all requests") and list candidate_count as unsupported on Gemini 3.x. In native mode GoModel builds the generationConfig itself, so it now leaves those four fields out for Gemini 3 and later and keeps forwarding them for Gemini 2.5, Gemma and other model IDs.

  • New geminiGeneration parser reads the <major>.<minor> generation from gemini-* IDs, including Vertex google/ prefixes, and dropsSamplingParameters gates on major >= 3.
  • max_tokens, stop, penalties, response_format and thinking settings are unchanged.
  • OpenAI-compatible mode is untouched; Google's own compatibility layer receives the body as-is.
  • Table-driven tests for the parser and the config builder, plus a docs note.

Caveat for reviewers: Google documents these parameters as "no longer recommended" and unsupported, not as returning HTTP 400 today. This is a proactive alignment with the migration guidance (mirrors #856 for Anthropic), and it changes behavior for callers that set temperature on a Gemini 3 model. Independent of #862, which fixes an actual 400 on reasoning_effort: minimal.

References: What's new in Gemini 3.5 Flash, What's new in Gemini 3.8 Flash.

Summary by CodeRabbit

  • Bug Fixes

    • Gemini 3 and later models no longer receive unsupported sampling parameters such as temperature, top-p, top-k, and candidate count.
    • Gemini 2.5, Gemma, and other supported models continue to honor these parameters.
    • Maximum output tokens, stop sequences, penalties, response formats, and thinking settings remain unaffected.
  • Documentation

    • Added guidance describing sampling-parameter behavior across Gemini model versions.

@mintlify

mintlify Bot commented Sep 2, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
gomodel 🟢 Ready View Preview Sep 2, 2026, 4:48 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@coderabbitai

coderabbitai Bot commented Sep 2, 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: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 72922997-ba06-4b3c-b0fd-b6381f0968fe

📥 Commits

Reviewing files that changed from the base of the PR and between a8fe362 and 5d60722.

📒 Files selected for processing (3)
  • docs/providers/gemini.mdx
  • internal/providers/gemini/native.go
  • internal/providers/gemini/native_sampling_test.go

Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The Gemini provider now omits selected sampling parameters for Gemini 3 and later models. Gemini 2.5 and non-Gemini models retain the previous behavior. Tests and provider documentation cover the model-specific behavior.

Changes

Gemini sampling parameters

Layer / File(s) Summary
Model generation detection and request filtering
internal/providers/gemini/native.go
The provider parses Gemini model generations and omits temperature, top_p, top_k, and candidate_count for Gemini 3 and later models.
Sampling behavior validation and documentation
internal/providers/gemini/native_sampling_test.go, docs/providers/gemini.mdx
Tests cover parsing and generation configuration behavior. The documentation describes the model-specific sampling rules and unaffected settings.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 5d607

The PR removes unsupported sampling fields from native Gemini 3 and later requests while preserving existing behavior for other models; no actionable merge-blocking risk remains after normal checks and review.

Poem

A rabbit reads each line,
The patch grows clear beneath the moon,
Small changes hop in place,
Tests guard the garden path,
Reviews bloom before the dawn.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 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 describes the main change: removing sampling parameters and candidate_count for Gemini 3 models.
Description check ✅ Passed The description is detailed, relevant, and covers the change, rationale, affected modes, preserved settings, tests, documentation, caveats, and references. It uses a "## Summary" heading instead of th…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is detailed, relevant, and covers the change, rationale, affected modes, preserved settings, tests, documentation, caveats, and references. It uses a "## Summary" heading instead of the template's required "## Description" heading, but the required information is present.

Full details: Docstring Coverage

Explanation

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

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/gemini-3-sampling-params

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.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 96.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/providers/gemini/native.go 96.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Sep 2, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The native Gemini request-generation behavior is safe to merge based on direct execution across relevant Gemini and control model identifiers.

Direct request-generation checks confirmed that Gemini 3+ identifiers omit the four intended fields while Gemini 2.5 and non-Gemini controls preserve them; focused package tests also passed.

Files Needing Attention: No files need follow-up attention.

T-Rex T-Rex Logs

What T-Rex did

  • Ran an authored Go test through the JSON core.ChatRequest to the native generation-config path for public, publisher-prefixed, full Vertex resource-path, and mixed-case Gemini 3+/4 identifiers, with Gemini 2.5, Gemma, and Imagen controls.
  • The harness showed that before the PR commit, temperature, topP, topK, and candidateCount were present for Gemini 3+/4, but after the PR commit those fields were absent for Gemini 3+/4 and retained for the controls.
  • Focused package tests for Gemini ran and passed, confirming the request-generation behavior and parser coverage.
  • No production files were changed; the authored test source was saved as a review artifact and the temporary in-package copy was removed after execution.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (1): Last reviewed commit: "fix(gemini): drop sampling parameters an..." | Re-trigger Greptile

@SantiagoDePolonia
SantiagoDePolonia merged commit 338ab6c into main Sep 2, 2026
20 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.

2 participants