← Blog

Gemini Prompt Feedback Needs a Block Reason Policy

Parminder Singh
Parminder Singh··5 min read
Summarize with AI

Gemini GenerateContent can return promptFeedback when content filters evaluate the submitted prompt. If blockReason is set, Google says the prompt was blocked and no candidates are returned. A production route should preserve the exact reason and prompt safety ratings, separate provider evidence from application messaging, and hold unknown or contradictory states for review.

Platform & Architectureai-securityllm-securitypolicy-enforcementzero-trustforensic-auditaudit
Gemini Prompt Feedback Needs a Block Reason Policy

Gemini places prompt-level content-filter evidence in promptFeedback. The GenerateContent schema says that when blockReason is set, the prompt was blocked and no candidates are returned. That response shape needs a distinct application path. Code that expects candidates[0] can turn a documented provider decision into a null error or a generic 500. It can also trigger a retry that sends the same rejected prompt again.

I want the route to classify prompt feedback before candidate parsing starts. The audit record should retain the raw block reason and prompt safety ratings. It should also retain the requested model, resolved model version, response ID, and local disposition.

TL;DR

  • Inspect promptFeedback.blockReason before reading the Gemini candidates array.
  • Treat a set block reason with no candidates as a prompt-block outcome, not a transport failure.
  • Preserve the raw reason and prompt safety ratings without collapsing every value into unsafe.
  • Hold unknown and contradictory states under a versioned per-route policy, with malformed states following the same hold.

Prompt feedback precedes candidate handling

Google AI Studio's GenerateContent API reference defines promptFeedback as feedback related to content filters. Its blockReason field is optional. When that field is set, the reference says the prompt was blocked and no candidates are returned. The same object can carry prompt safetyRatings, with at most one rating per category.

That contract gives the parser a clear order. Validate the response envelope before inspecting prompt feedback, then begin candidate selection only when the prompt path permits it and the candidates array has a valid shape. A blocked prompt belongs in the operation record even though it produced no candidate content.

Represent absence with block_reason_present: false. That differs from a synthetic value such as NONE, because Google reserves enum values and can extend the schema. The AI audit log schema provides the common identity, route, policy, and timestamp fields around this provider evidence.

Block reasons need separate dispositions

The current reference lists SAFETY, BLOCKLIST, PROHIBITED_CONTENT, IMAGE_SAFETY, OTHER, and BLOCK_REASON_UNSPECIFIED. Retaining the exact string allows each reason to share a user-facing message while still driving a different review queue and metric.

For SAFETY, preserve the accompanying prompt safety ratings permitted by the route's evidence policy. BLOCKLIST describes terms included in a terminology blocklist. PROHIBITED_CONTENT and IMAGE_SAFETY deserve their own operational categories. OTHER says the provider blocked for an unknown reason, which makes it poor evidence for a more specific internal claim. The unspecified value should enter a named hold path if it appears as an active reason.

My blunt opinion is that mapping all six values to content_error is careless engineering. It erases the distinction Google supplied and leaves the on-call engineer guessing during a review.

The per-route AI policies guide is the right place to assign allowed reasons, user messaging, evidence retention, and escalation ownership.

Safety ratings explain a safety block

Google's safety settings guide documents adjustable harm categories and blocking thresholds. It also explains blocked-content handling. Request settings and returned prompt ratings belong together because the response alone cannot reconstruct which thresholds the application sent.

Capture the provider-bound safety settings after policy compilation, including omitted categories. Then retain each returned prompt rating as its own category row. A SAFETY block can point reviewers to those ratings without turning a probability label into a severity judgment. An application may add its own risk classification, but that value needs a separate field, method, and owner.

Some provider protections remain built in. The safety guide explains that adjustable settings do not cover every protection. The audit should therefore report observed request fields and returned evidence, rather than claim that the application controlled every provider-side decision.

A narrow review screen helps here. Show the raw block reason on a white card, then place each category rating on a separate line beneath it. An empty gray box labeled no candidates returned is more honest than a green candidate panel with blank text.

User messages should reveal less than audit records

The application can return a stable client error without exposing filter internals. A caller may need to know that the prompt was rejected and can be revised. They rarely need the exact blocklist term, internal policy version, or full prompt copied into an error body.

Keep three layers distinct. Provider evidence contains the raw Gemini fields. Application disposition records withheld, review, or rejected under a named policy version. Client messaging uses a bounded error code and support text approved for that route. This separation limits information disclosure and allows product wording to change without rewriting historical evidence.

Prompts can contain source code, customer records, or regulated data. Retain raw text only where the route's storage and access policy permits it. A protected digest, restricted content reference, request size, and classification result may supply enough evidence for routine review. Ticket titles and metrics labels should exclude prompt text.

This handling also prevents accidental retries. A deterministic content-filter response has reached a decision. The safe idempotent LLM retries guide covers ambiguous transport outcomes; a documented prompt block belongs to a new, user-edited request rather than a blind replay.

Contradictory response shapes require quarantine

A validator should expect a set blockReason to coincide with no candidates, as stated in the API reference. Fixtures must still cover malformed and future shapes. Return a block reason with a non-empty candidates array and verify that delivery stops while the raw response is retained. Then return safety ratings with duplicate categories, an unknown category, and a non-string reason.

Add a case where SAFETY appears without ratings. The route can classify it as prompt_blocked_safety_ratings_absent rather than inventing category evidence. Test OTHER and an unknown enum such as VENDOR_NEW_REASON; both should remain verbatim. A strict route can quarantine them until policy owners review the current Google contract.

Streaming needs the same discipline at assembly time. If a client has already displayed provisional bytes before a terminal prompt-block state appears, record the delivered byte count and stop downstream actions. Never relabel an incomplete or contradictory stream as a normal candidate completion.

The release gate should assert the application error code, audit row, retention behavior, and absence of candidate execution for every fixture. HTTP 200 merely confirms transport success. Prompt feedback still decides what the application can do next.

DeepInspect

DeepInspect can inspect GenerateContent responses on authenticated user or agent Gemini HTTP traffic deliberately routed through its proxy. It can evaluate prompt feedback before candidate delivery, enforce route-specific handling for allowed block reasons, and write a per-decision audit record tied to caller identity and policy version.

The application owns prompt editing, user-facing error text, human review, raw-content retention, and any action after a response leaves the routed exchange. Direct Gemini calls and local processing that bypass the proxy remain outside DeepInspect's enforcement and evidence.

Book a technical deep dive at deepinspect.ai.

Frequently asked questions

What does Gemini promptFeedback contain?

The GenerateContent reference describes promptFeedback as content-filter feedback for the prompt. It can include an optional blockReason and prompt safety ratings, with at most one rating per category.

Does a blockReason mean the API request failed?

A block reason reports a prompt-filter outcome inside the Gemini response. Treat it as a completed provider decision that requires application handling, even when the HTTP exchange succeeded and no candidates were returned.

Should an application retry a blocked prompt automatically?

A blind retry repeats the same rejected content and can spend request budget without changing the decision. Offer an edited request where appropriate, assign it a new operation ID, and link it to the original blocked attempt.

What should happen when Gemini returns an unknown block reason?

Preserve the raw value, stop delivery under a fail-closed route, and review the current API contract before adding a disposition. Coercing a new value to OTHER destroys evidence about provider change.