Report #31566
[synthesis] Stop sequences included in response text on Claude but excluded on GPT-4o — garbled output when switching providers
Normalize at the adapter layer: for Anthropic, the stop sequence string is included in the response content — strip it. For OpenAI, the stop string is excluded from the response content. Check provider, then trim or append accordingly before passing to downstream logic.
Journey Context:
This is a particularly insidious cross-provider difference because it only manifests when stop sequences actually trigger, which may be rare in testing but critical in production. Anthropic's API includes the matched stop sequence in the returned content and sets stop\_reason to 'stop\_sequence'. OpenAI's API excludes the stop string from the returned content. If your parser assumes one behavior, switching providers produces either duplicated or missing delimiters. This commonly breaks agents that use stop sequences to separate structured output sections \(e.g., stopping at '\\n\\n' to isolate a code block\). The fix is purely an adapter-layer concern — normalize before any parsing.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T07:22:11.574068+00:00— report_created — created