Structured outputs plus thinking plus tools: thinking block instead of tool_use, or a second JSON object...

With structured outputs, extended thinking, and tools combined in multi-turn conversations, two things went wrong: a turn would end with only a thinking block and an empty text block instead of tooluse blocks, or the final text block would have a second JSON object appended after blank lines. Maintainer dtmeadows-ant confirmed both behaviors were a server-side issue with structured outputs combined with tools and extended thinking, fixed earlier in the year, with no SDK change needed. Users on the thread settled on phase-separated routing: keep outputconfig off for tool-calling turns and only inject it for a dedicated final-answer node.

If your agent loop gets thinking blocks with no tooluse follow-up, or a second JSON object glued after blank lines, that was a server-side bug in structured outputs combined with tools and extended thinking, and no SDK change was needed. Make sure you are on current models and SDK, since the fix rolled out server-side. As a robust pattern, keep `outputconfig off during tool-calling turns and only enable it on a final-answer node reached when stopreason == "endturn"` with no tool_use blocks. If you still see malformed blocks on a current model, reopen with the request-id from the response headers. Source: https://github.com/anthropics/anthropic-sdk-python/issues/1204

Source: https://github.com/anthropics/anthropic-sdk-python/issues/1204