Skip to content

Fix/fix anthropic payload handler#724

Merged
cosminacho merged 6 commits intomainfrom
fix/fix_anthropic_payload_handler
Mar 24, 2026
Merged

Fix/fix anthropic payload handler#724
cosminacho merged 6 commits intomainfrom
fix/fix_anthropic_payload_handler

Conversation

@cosminacho
Copy link
Contributor

@cosminacho cosminacho commented Mar 24, 2026

Problem

A regression was introduced in the thinking_enabled detection logic inside
BedrockInvokePayloadHandler and BedrockConversePayloadHandler. The original
code used a chained .get() with an or {} fallback:

thinking_enabled = (
    getattr(self.model, "model_kwargs", {}).get("thinking", {}).get("type")
    == "enabled"
)

The or {} fallback only fires for falsy values (None, False, 0,
{}). If the thinking key is present but holds a non-None, non-dict truthy
value — e.g. a plain string "enabled", a list, or an integer — the fallback
is skipped and .get("type") is called on a type that doesn't support it,
raising an AttributeError at inference time.

This manifested as a runtime crash for Anthropic models on Bedrock where the
thinking field was set to an unexpected shape.

Fix
Replace the or {} chain with an explicit isinstance guard:

_thinking = (getattr(self.model, "model_kwargs", None) or {}).get("thinking")
thinking_enabled = isinstance(_thinking, dict) and _thinking.get("type") == "enabled"

@cosminacho cosminacho force-pushed the fix/fix_anthropic_payload_handler branch from 300dec8 to 03ee5ed Compare March 24, 2026 15:17
@cosminacho cosminacho force-pushed the fix/fix_anthropic_payload_handler branch from 03ee5ed to 1d62695 Compare March 24, 2026 15:17
Copy link
Contributor

@ionut-mihalache-uipath ionut-mihalache-uipath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not the best readable code, but it works

@cosminacho cosminacho merged commit 8ff4412 into main Mar 24, 2026
42 checks passed
@cosminacho cosminacho deleted the fix/fix_anthropic_payload_handler branch March 24, 2026 15:47
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.

2 participants