fix(anthropic): detect invalid thinking signatures from Vertex AI error format

Remove the `"block"` keyword requirement from is_anthropic_invalid_thinking_signature_error.
The Vertex AI error format uses "messages.N.content.M.thinking.signature.str: Input should be a valid string"
which contains "invalid", "signature", and "thinking" but not "block". The triple combination
is already specific enough to avoid false positives.

Fixes #26005
This commit is contained in:
elvis 2026-04-21 14:59:06 +10:00
parent b9bedc8153
commit 8cf495df04
2 changed files with 17 additions and 3 deletions

View file

@ -763,8 +763,9 @@ def is_anthropic_invalid_thinking_signature_error(error_text: str) -> bool:
Detect Anthropic 400 when encrypted thinking signatures in history do not match
the current deployment (e.g. user rotated API key or switched model endpoint).
Example API message:
messages.N.content.M: Invalid `signature` in `thinking` block
Example API messages:
- messages.N.content.M: Invalid `signature` in `thinking` block
- messages.N.content.M.thinking.signature.str: Input should be a valid string
"""
if not error_text:
return False
@ -773,7 +774,6 @@ def is_anthropic_invalid_thinking_signature_error(error_text: str) -> bool:
"invalid" in lower
and "signature" in lower
and "thinking" in lower
and "block" in lower
)

View file

@ -1153,6 +1153,20 @@ class TestAnthropicThinkingSignatureSelfHeal:
)
assert is_anthropic_invalid_thinking_signature_error(raw) is True
def test_is_anthropic_invalid_thinking_signature_error_vertex_ai(self):
"""Vertex AI returns a different error format for invalid thinking signatures."""
from litellm.llms.anthropic.common_utils import (
is_anthropic_invalid_thinking_signature_error,
)
raw = (
'{"type":"error","error":{"type":"invalid_request_error",'
'"message":"messages.1.content.0.thinking.signature.str: '
'Input should be a valid string"},'
'"request_id":"req_vrtx_011CaB4qJPWdYMoM8yyQUQ5C"}'
)
assert is_anthropic_invalid_thinking_signature_error(raw) is True
def test_is_anthropic_invalid_thinking_signature_error_negative(self):
from litellm.llms.anthropic.common_utils import (
is_anthropic_invalid_thinking_signature_error,