can1357/oh-my-pi · error · AIError.ProviderResponseError

Request blocked by Google (${chunk.promptFeedback.blockReaso

Error message

Request blocked by Google (${chunk.promptFeedback.blockReason})${detail ? `: ${detail}` : ""}

What it means

consumeGoogleStream received a chunk with no candidates but a promptFeedback.blockReason, meaning Google refused the request outright (prompt filtered before generation). The library throws AIError.ProviderResponseError with kind "content-blocked" and includes the block reason (e.g. SAFETY, RECITATION, BLOCKLIST, PROHIBITED_CONTENT) plus any blockReasonMessage detail.

Source

Thrown at packages/ai/src/providers/google-shared.ts:626

				currentBlock.thinking += tail;
				stream.push({ type: "thinking_delta", contentIndex: blockIndex(), delta: tail, partial: output });
			}
		}
		thinkingStripper = null;
		pushBlockEndEvent(currentBlock, blockIndex(), output, stream);
	};

	for await (const chunk of googleStream) {
		if (chunk.error) {
			const detail = chunk.error.message || chunk.error.status || "unknown error";
			const message = `Google API stream error: ${detail}`;
			throw typeof chunk.error.code === "number" && chunk.error.code >= 400
				? new AIError.GoogleApiError(message, chunk.error.code)
				: new AIError.ProviderResponseError(message, { provider: model.provider, kind: "output" });
		}
		if (!chunk.candidates?.length && chunk.promptFeedback?.blockReason) {
			const detail = chunk.promptFeedback.blockReasonMessage;
			throw new AIError.ProviderResponseError(
				`Request blocked by Google (${chunk.promptFeedback.blockReason})${detail ? `: ${detail}` : ""}`,
				{ provider: model.provider, kind: "content-blocked" },
			);
		}
		const candidate = chunk.candidates?.[0];
		if (candidate?.content?.parts) {
			for (const part of candidate.content.parts) {
				if (part.text !== undefined && part.text !== "") {
					if (!firstTokenSeen) {
						firstTokenSeen = true;
						onFirstToken?.();
					}
					const isThinking = isThinkingPart(part);
					if (
						!currentBlock ||
						(isThinking && currentBlock.type !== "thinking") ||
						(!isThinking && currentBlock.type !== "text")
					) {

View on GitHub (pinned to 9690622007)

Solutions

  1. Inspect blockReason/blockReasonMessage in the thrown error's context and revise the prompt content
  2. Lower safety thresholds via safetySettings on the request where policy allows
  3. Catch AIError.ProviderResponseError and branch on kind === "content-blocked" to show a user-facing block message
  4. Test the same prompt against the Google AI Studio playground to confirm filtering behavior

Example fix

// before
const result = await streamGoogle(model, params); // throws on block
// after
try {
  const result = await streamGoogle(model, params);
} catch (err) {
  if (err instanceof AIError.ProviderResponseError && err.context?.kind === "content-blocked") {
    return { blocked: true, reason: err.message };
  }
  throw err;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// client-side pre-screen cannot replicate Google's filters, but you can branch on the thrown kind:
function isContentBlocked(err: unknown) {
  return err instanceof AIError.ProviderResponseError && (err.context as any)?.kind === "content-blocked";
}

Type guard

function isBlockFeedback(chunk: GoogleStreamChunk): boolean {
  return !chunk.candidates?.length && Boolean(chunk.promptFeedback?.blockReason);
}

Try / catch

try {
  const stream = await streamGoogle(model, params);
} catch (err) {
  if (isContentBlocked(err)) {
    return { blocked: true, detail: err.message }; // show user why their prompt was refused
  }
  throw err;
}

Prevention

When it happens

Trigger: Streaming a generateContent request where Google's safety systems block the prompt: chunk.candidates is empty and chunk.promptFeedback.blockReason is set (typically SAFETY or BLOCKLIST).

Common situations: Prompts containing flagged content (violence, personal info, copyrighted text); over-aggressive safety thresholds; non-English prompts misclassified; changes in Google's safety filters over time.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/976817869bfdf5cb. Report an issue: GitHub.