[PR #7544] [MERGED] fix(gemini): always turn Gemini safety filters off #7785

Closed
opened 2026-10-24 04:07:29 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7544
Author: @SpicyMarinara
Created: 10/13/2026
Status: ✅ Merged
Merged: 10/13/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/gemini-safety-off


📝 Commits (3)

  • 7435f2a fix(gemini): always turn Gemini safety filters off (#7542)
  • 0ed7daf docs(gemini): note that Custom Parameters can set their own safety settings
  • bf94340 Merge branch 'staging' into fix/gemini-safety-off

📊 Changes

3 files changed (+52 additions, -4 deletions)

View changed files

📝 docs/connections/providers-reference.md (+2 -0)
📝 packages/server/src/services/llm/providers/google.provider.ts (+18 -0)
📝 scripts/regressions/provider-compat.regression.ts (+32 -4)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7542

Follow-up: #7552 keeps the unnamed categories Off when Custom Parameters set only some of them.

Why this change

  • Marinara sent no safety settings to Gemini, so every request used Google's default filters. Google documents that default as Off only for Gemini 2.5 and 3 (safety settings). Newer models such as Gemini 4 Argon have no documented default, so Google could block replies on them that Gemini 3 allows.
  • Mari decided on 2026-10-13 that Gemini safety filters must always be off, with no setting for it.

What changed

  • google.provider.ts has one constant and one helper. Every Google AI Studio and Vertex AI generateContent / streamGenerateContent request now carries safetySettings with threshold OFF for HARM_CATEGORY_HARASSMENT, HARM_CATEGORY_HATE_SPEECH, HARM_CATEGORY_SEXUALLY_EXPLICIT and HARM_CATEGORY_DANGEROUS_CONTENT. Both request builders call it: the chat builder (streaming and non-streaming) and the tool-calling round. The connection test goes through the same chat builder.
  • The helper runs after custom parameters. If a user's own custom parameters already set safetySettings or safety_settings, those are kept and Marinara does not add a second copy.
  • OFF is used, not BLOCK_NONE, because the API reference describes OFF as "Turn off the safety filter" and Vertex has restricted BLOCK_NONE in the past.
  • Two categories are left out on purpose. HARM_CATEGORY_CIVIC_INTEGRITY is marked deprecated in the API reference ("use enableEnhancedCivicAnswers instead"). HARM_CATEGORY_JAILBREAK is in the reference but not in the guide's list of adjustable categories. Sending either one could cause a 400 on some catalog model, and there is no way to rule that out without live calls.
  • Core protections, such as child safety, cannot be turned off. When Google still blocks a reply, the existing promptFeedback.blockReason / finish-reason errors still show Google's reason.
  • Docs: one sentence in docs/connections/providers-reference.md. The translation follow-up is #7543.

Routes checked and left unchanged (known gaps)

  • OpenRouter (chat and Gemini image models): I found no documented Gemini safety field a caller can send. Correction after merge: the chat API reference does list provider.options keyed by provider slug, including google-ai-studio and google-vertex, each open-ended. Only options for the matched provider are forwarded, and unrecognised keys are dropped. No Gemini safety key is documented under it. The parameters reference names only Mistral safe_prompt and Hyperbolic raw_mode as provider-specific passthroughs. Following the decision not to guess, OpenRouter request bodies are unchanged, so non-Gemini bodies are byte-identical to before. require_parameters is not touched.
  • NanoGPT and Custom (OpenAI-compatible) connections serving Gemini (added after merge): both use the OpenAI-compatible provider, and their bodies are unchanged. NanoGPT's chat reference documents no safety or Gemini passthrough field.
  • Google's OpenAI-compatible endpoint and Gemini image models through OpenAI-compatible proxies (gemini_image): Google's OpenAI compatibility page documents extra_body.google.safety_settings only for the Images endpoint, not for chat completions. Marinara's Gemini image path posts to /chat/completions, so nothing documented applies there.
  • Gemini Omni video: this route uses the Interactions API, not generateContent, and the Interactions overview says "Custom safety settings are not supported in the Interactions API." Veo uses predictLongRunning, which has no safetySettings field.
  • Embeddings (embedContent) and model listing: safety settings do not apply to these calls.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Commands the agent ran (results only; the boxes above are for a human to tick):

  • pnpm check: exit 0.
  • Local CodeRabbit (coderabbit review --agent --committed --base-commit origin/staging): 1 minor finding. The docs sentence said "always" even though the user's own Custom Parameters win. Fixed by naming that exception in the docs sentence.
  • node ./scripts/run-regressions.mjs --filter provider-compat: passed. The Gemini 4 Argon request-shape block now pins safetySettings on AI Studio and Vertex for non-streaming, streaming and the tools round. A new case proves a user's own safety_settings is kept and not doubled. The pinned Gemini 3 bytes now include the safety settings and are otherwise unchanged. Before the expectations were updated, the same block failed on the new field, which shows the request body really changed.
  • --filter provider-caching, generation-parameter-relevance, mari-completion-frames, agent-connection-parameters, game-tool-controls, open-issues, agent-activation (2 files), spatial-context: all passed.
  • No live requests were sent to Google or OpenRouter. All bodies were checked against a stubbed fetch.

Manual verification notes

  • Send a Gemini message on a Google Gemini (AI Studio) connection and confirm content that Google blocked before now gets a reply with no safety block. Try Gemini 4 Argon if available.
  • Do the same on a Google Vertex AI connection.
  • Do the same with a Gemini model on OpenRouter. This PR does not change OpenRouter, so a block there would confirm the known gap above.
  • Use Test Message on a Google Gemini connection and confirm it still succeeds.
  • With debug mode on, confirm the logged Gemini tools request includes safetySettings with OFF for the four categories.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Docs follow-up: #7543 ([docs-i18n] docs/connections/providers-reference.md).

UI evidence (if applicable)

Not applicable (server request bodies only).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7544 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/13/2026 **Status:** ✅ Merged **Merged:** 10/13/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/gemini-safety-off` --- ### 📝 Commits (3) - [`7435f2a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7435f2a5b83c1d31c7e7219beeb0245db301c454) fix(gemini): always turn Gemini safety filters off (#7542) - [`0ed7daf`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0ed7daf10c655288034217e359069c6d42093c83) docs(gemini): note that Custom Parameters can set their own safety settings - [`bf94340`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bf943402cd04774ff801b473c736daf8c88ac51a) Merge branch 'staging' into fix/gemini-safety-off ### 📊 Changes **3 files changed** (+52 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `docs/connections/providers-reference.md` (+2 -0) 📝 `packages/server/src/services/llm/providers/google.provider.ts` (+18 -0) 📝 `scripts/regressions/provider-compat.regression.ts` (+32 -4) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #7542 Follow-up: #7552 keeps the unnamed categories Off when Custom Parameters set only some of them. ## Why this change - Marinara sent no safety settings to Gemini, so every request used Google's default filters. Google documents that default as Off only for Gemini 2.5 and 3 ([safety settings](https://ai.google.dev/gemini-api/docs/safety-settings)). Newer models such as Gemini 4 Argon have no documented default, so Google could block replies on them that Gemini 3 allows. - Mari decided on 2026-10-13 that Gemini safety filters must always be off, with no setting for it. ## What changed - `google.provider.ts` has one constant and one helper. Every Google AI Studio and Vertex AI `generateContent` / `streamGenerateContent` request now carries `safetySettings` with threshold `OFF` for `HARM_CATEGORY_HARASSMENT`, `HARM_CATEGORY_HATE_SPEECH`, `HARM_CATEGORY_SEXUALLY_EXPLICIT` and `HARM_CATEGORY_DANGEROUS_CONTENT`. Both request builders call it: the chat builder (streaming and non-streaming) and the tool-calling round. The connection test goes through the same chat builder. - The helper runs after custom parameters. If a user's own custom parameters already set `safetySettings` or `safety_settings`, those are kept and Marinara does not add a second copy. - `OFF` is used, not `BLOCK_NONE`, because the API reference describes `OFF` as "Turn off the safety filter" and Vertex has restricted `BLOCK_NONE` in the past. - Two categories are left out on purpose. `HARM_CATEGORY_CIVIC_INTEGRITY` is marked deprecated in the [API reference](https://ai.google.dev/api/generate-content#v1beta.HarmCategory) ("use enableEnhancedCivicAnswers instead"). `HARM_CATEGORY_JAILBREAK` is in the reference but not in the guide's list of adjustable categories. Sending either one could cause a 400 on some catalog model, and there is no way to rule that out without live calls. - Core protections, such as child safety, cannot be turned off. When Google still blocks a reply, the existing `promptFeedback.blockReason` / finish-reason errors still show Google's reason. - Docs: one sentence in `docs/connections/providers-reference.md`. The translation follow-up is #7543. ### Routes checked and left unchanged (known gaps) - **OpenRouter (chat and Gemini image models):** I found no documented Gemini safety field a caller can send. Correction after merge: the [chat API reference](https://openrouter.ai/docs/api/api-reference/chat/send-chat-completion-request) does list `provider.options` keyed by provider slug, including `google-ai-studio` and `google-vertex`, each open-ended. Only options for the matched provider are forwarded, and unrecognised keys are dropped. No Gemini safety key is documented under it. The [parameters reference](https://openrouter.ai/docs/api/reference/parameters) names only Mistral `safe_prompt` and Hyperbolic `raw_mode` as provider-specific passthroughs. Following the decision not to guess, OpenRouter request bodies are unchanged, so non-Gemini bodies are byte-identical to before. `require_parameters` is not touched. - **NanoGPT and Custom (OpenAI-compatible) connections serving Gemini** (added after merge): both use the OpenAI-compatible provider, and their bodies are unchanged. NanoGPT's [chat reference](https://docs.nano-gpt.com/api-reference/endpoint/chat-completion) documents no safety or Gemini passthrough field. - **Google's OpenAI-compatible endpoint and Gemini image models through OpenAI-compatible proxies (`gemini_image`):** Google's [OpenAI compatibility](https://ai.google.dev/gemini-api/docs/openai) page documents `extra_body.google.safety_settings` only for the Images endpoint, not for chat completions. Marinara's Gemini image path posts to `/chat/completions`, so nothing documented applies there. - **Gemini Omni video:** this route uses the Interactions API, not `generateContent`, and the [Interactions overview](https://ai.google.dev/gemini-api/docs/interactions-overview) says "Custom safety settings are not supported in the Interactions API." Veo uses `predictLongRunning`, which has no `safetySettings` field. - **Embeddings (`embedContent`) and model listing:** safety settings do not apply to these calls. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Commands the agent ran (results only; the boxes above are for a human to tick): - `pnpm check`: exit 0. - Local CodeRabbit (`coderabbit review --agent --committed --base-commit origin/staging`): 1 minor finding. The docs sentence said "always" even though the user's own Custom Parameters win. Fixed by naming that exception in the docs sentence. - `node ./scripts/run-regressions.mjs --filter provider-compat`: passed. The Gemini 4 Argon request-shape block now pins `safetySettings` on AI Studio and Vertex for non-streaming, streaming and the tools round. A new case proves a user's own `safety_settings` is kept and not doubled. The pinned Gemini 3 bytes now include the safety settings and are otherwise unchanged. Before the expectations were updated, the same block failed on the new field, which shows the request body really changed. - `--filter provider-caching`, `generation-parameter-relevance`, `mari-completion-frames`, `agent-connection-parameters`, `game-tool-controls`, `open-issues`, `agent-activation` (2 files), `spatial-context`: all passed. - No live requests were sent to Google or OpenRouter. All bodies were checked against a stubbed `fetch`. ### Manual verification notes - Send a Gemini message on a **Google Gemini (AI Studio)** connection and confirm content that Google blocked before now gets a reply with no safety block. Try Gemini 4 Argon if available. - Do the same on a **Google Vertex AI** connection. - Do the same with a Gemini model on **OpenRouter**. This PR does not change OpenRouter, so a block there would confirm the known gap above. - Use **Test Message** on a Google Gemini connection and confirm it still succeeds. - With debug mode on, confirm the logged Gemini tools request includes `safetySettings` with `OFF` for the four categories. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) Docs follow-up: #7543 (`[docs-i18n] docs/connections/providers-reference.md`). ## UI evidence (if applicable) Not applicable (server request bodies only). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:07:29 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7785
No description provided.