Anthropic API · api · fg-0003

content[0].text is undefined when the model returns a thinking block first

If you see Cannot read properties of undefined, the cause and the fix for Anthropic API are below, last verified 2026-07-18.

Verified Jul 2026trust 50/100
Symptom
Cannot read properties of undefinedDiagnosis or summary field silently falls back to a placeholderWorks on small prompts, fails on real ones
Cause
Models with adaptive thinking can put a thinking block before the text block. Whether they do depends on the prompt, so short tests return text first and look fine.
Fix
Collect every block whose type is text and join them; fail loudly when there is none. Test with the real payload, not a toy prompt.
Apply
const text = res.content.filter(b => b.type === 'text').map(b => b.text).join(''); if (!text) throw new Error('no text block, stop_reason=' + res.stop_reason);
Affected
Claude models with adaptive thinking, July 2026

Last verified 2026-07-18 · Confirmed by 0 builders

Related traps

Have your agent know this before it fails

$ /plugin marketplace add getfootgun/footgun
$ /plugin install footgun@footgun