Submit a toolSubmit

Gemini API returned 400 with code safety. Adjust filters or rewrite the input—don’t retry blind

A safety, jailbreak, prohibited_content, or blocklist block returns HTTP 400 and no text. Read the code, ease filters when allowed, then rewrite—don’t retry. Short answer: 5 steps. 1) Read error.code before you change the prompt; 2) Don’t confuse it with 429 RESOURCE_EXHAUSTED or an invalid key; 3) Inspect which category you tightened—and what you can actually change; 4) Rewrite or shrink the input when the code is jailbreak / prohibited_content / blocklist; 5) Handle 400 safety in code as non-retryable until the request changes.

Last updated: · This page is the decision checklist; the tools list for “Fix a Gemini API 400 safety / content block” is a separate URL.

The problem: A safety, jailbreak, prohibited_content, or blocklist block returns HTTP 400 and no text. Read the code, ease filters when allowed, then rewrite—don’t retry.

How do I adjust filters or rewrite the input when Gemini returns 400 safety?

  1. Read error.code before you change the prompt

    On the Gemini Interactions API, a safety filter that blocks the input or the response fails the call with HTTP 400 and does not return the blocked content. `code: "safety"` means an adjustable safety filter fired; `jailbreak`, `prohibited_content`, or `blocklist` mean the input was blocked for that reason (messages often start with “Input blocked:”). Docs: https://ai.google.dev/gemini-api/docs/safety-settings

  2. Don’t confuse it with 429 RESOURCE_EXHAUSTED or an invalid key

    A safety 400 is a content decision, not a quota or auth failure. Pace and quota errors are covered separately (for example RESOURCE_EXHAUSTED). If the key itself is wrong you get a different invalid-key path—fix billing/auth first only when the status and message say so. Quota errors: https://ai.google.dev/gemini-api/docs/quota-error-codes

  3. Inspect which category you tightened—and what you can actually change

    Pass `safety_settings` with one threshold per category (`harassment`, `hate_speech`, `sexually_explicit`, `dangerous_content`, `jailbreak`). Categories you omit default to Off on Gemini 2.5 and later. Built-in blocks for core harms (such as child-safety endangerment) cannot be relaxed. Looser settings may be subject to Google’s Terms review.

  4. Rewrite or shrink the input when the code is jailbreak / prohibited_content / blocklist

    Those codes point at the prompt, not a tunable threshold you should crank to Off. Remove jailbreak-style instructions, prohibited material, and blocklisted terms; then retry once. Blind retries with the same payload keep returning 400 and burn quota.

  5. Handle 400 safety in code as non-retryable until the request changes

    Branch on HTTP 400 + `error.code` in `safety` / `jailbreak` / `prohibited_content` / `blocklist`. Surface the message to the user or logs, adjust `safety_settings` only for legitimate product needs, and only then send a modified request. For background interactions, check `status: failed` and the same codes in `errors`; on streams, watch for an `error` event.

Which tools are best to fix a Gemini API 400 safety / content block?

Gemini safety settings

Categories, thresholds, and how blocked interactions return HTTP 400.

Gemini troubleshooting

General API failure patterns and next steps.

Quota and error codes

Keep RESOURCE_EXHAUSTED and related quota errors separate from safety 400s.

Google AI Studio API keys

Confirm you’re testing with a valid project key after content blocks are fixed.

All tools for “Fix a Gemini API 400 safety / content block” →

Related fixes

See also AI tools launched today on the daily board.