Skip to main content

Function: isContentPolicyRefusal()

isContentPolicyRefusal(error): boolean

Defined in: packages/agentos/src/api/generateText.ts:706

Internal

Detect content-policy refusals across providers so the fallback chain can route them to a more permissive model (typically uncensored OpenRouter for mature/private-adult callers). The provider matrix:

  • OpenAI: HTTP 400 with error.code: 'content_policy_violation' or error.type: 'content_policy_violation'. Also surfaces as a 400 with a safety_violations block on the structured-output path, which message-greps catch via "content_policy".
  • Anthropic: HTTP 400 with messages like "blocked by Anthropic's usage policies" or "violates safety guidelines". Recent SDKs also emit error.type: 'content_filter'.
  • Gemini: Doesn't error — instead returns finishReason: 'SAFETY' in the response. Caller-side detection catches that path; this helper only matches the error-shaped variants because the fallback chain only fires on thrown errors.
  • OpenRouter: forwards the upstream provider's error mostly verbatim, so the OpenAI/Anthropic patterns above also catch OpenRouter routes against gpt-4o / claude.

Returns true when the message + typed fields together indicate a content-policy refusal. The caller (the fallback loop in generateText) treats this as "retryable in the policy sense" so a content-policy fallback chain can fire on a 400 even though the network fallback chain wouldn't.

Parameters

error

unknown

Returns

boolean