Skip to content

detectRefusal

detectRefusal(message): RefusalInfo | null

Defined in: _worktrees/docs-release/gaunt-sloth/packages/core/src/core/refusal.ts:84

Inspect a finished model message (an AIMessage / AIMessageChunk, or any object exposing response_metadata / additional_kwargs) and return a RefusalInfo when its stop/finish reason indicates a content-policy refusal, else null. Defensive: any non-message / unexpected shape yields null, so a normal turn is never mistaken for a refusal.

Covered shapes:

  • OpenAI-family finish_reason: 'content_filter' (also under additional_kwargs).
  • Anthropic stop_reason: 'refusal'.
  • Bedrock Converse guardrail intervention: stopReason/stop_reason/finish_reason === 'guardrail_intervened', or additional_kwargs['amazon-bedrock-guardrailAction'] === ‘INTERVENED’`.
  • Bedrock Converse content filter: stopReason/stop_reason/finish_reason === 'content_filtered' (EXT-41 — a distinct StopReason enum value from guardrail_intervened that was previously mapped to null, i.e. a silent empty turn / false negative).

unknown

RefusalInfo | null