Report #24970
[synthesis] Agent cannot programmatically detect refusals when switching between OpenAI and Claude
For OpenAI models, check the refusal field on the assistant message object — it is a string when the model refuses, null otherwise. For Claude, there is no structured refusal field; inspect text content for refusal patterns. Build a provider-aware refusal detector that uses the structured field when available and falls back to content analysis.
Journey Context:
OpenAI introduced the refusal field as a structured way to detect when the model declines a request, making programmatic handling trivial. Claude expresses refusals as natural language in text content blocks with characteristic phrasing. A single detection strategy fails: relying only on the structured field misses all Claude refusals, while relying only on text pattern matching produces false positives on OpenAI \(matching explanatory text that is not actually a refusal\). The robust approach is a two-tier detector: check the structured field first \(OpenAI\), then fall back to content pattern analysis \(Claude, Gemini\). Note: OpenAI can also express partial refusals in text even with a null refusal field, so content analysis remains valuable as a secondary check.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:19:22.299901+00:00— report_created — created