Skip to content

fix(parser): handle missing signature field in ThinkingBlock#786

Open
nanookclaw wants to merge 1 commit intoanthropics:mainfrom
nanookclaw:fix/thinking-block-missing-signature
Open

fix(parser): handle missing signature field in ThinkingBlock#786
nanookclaw wants to merge 1 commit intoanthropics:mainfrom
nanookclaw:fix/thinking-block-missing-signature

Conversation

@nanookclaw
Copy link
Copy Markdown

Summary

Fixes a KeyError: 'signature' crash in message_parser.py when the API returns a thinking content block without a signature field.

Root Cause

message_parser.py:110 uses a direct dict lookup:

signature=block["signature"],  # KeyError if field absent

The Anthropic API can return thinking blocks without a signature in certain conditions:

  • Redacted thinking blocks (policy-based)
  • Streaming edge cases
  • Older cached responses

Fix

One-line change to use .get() with an empty string default:

signature=block.get("signature", ""),

Test

Added test_parse_assistant_message_with_thinking_missing_signature in the existing test suite — verifies that parsing succeeds (no KeyError) when signature is absent from a thinking block.

All 453 existing tests pass.

Related

Fixes the KeyError: 'signature' reported in #777 by @Zerolzj.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant