Report #31190
[synthesis] Agent can't detect why model stopped generating — stop\_reason strings differ across providers and break conditional logic
Map every provider's native stop reason to a canonical enum at your adapter layer before any downstream logic sees it: OpenAI stop→COMPLETE, length→TRUNCATED, tool\_calls→TOOL\_CALL, content\_filter→FILTERED; Anthropic end\_turn→COMPLETE, max\_tokens→TRUNCATED, stop\_sequence→COMPLETE, tool\_use→TOOL\_CALL. Never compare raw stop\_reason strings in business logic.
Journey Context:
If your agent checks \`if stop\_reason === 'stop'\` it will silently fail on Claude \(which uses 'end\_turn'\) and the agent falls through to error handling or an infinite loop. The same happens in reverse. This is especially dangerous because the failure mode is silent — no error is thrown, the agent just takes the wrong branch. Some teams try string matching with includes\(\) or regex, but that's fragile when providers add new stop reasons. The canonical enum pattern at the model adapter layer is the only approach that scales. Also note: Anthropic has no equivalent to OpenAI's 'content\_filter' stop reason — filtered responses appear as normal refusals with 'end\_turn'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T06:44:26.014363+00:00— report_created — created