Skip to content

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

Closed
elvis-cai wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
elvis-cai:fix/anthropic-vertex-thinking-signature-error
Closed

elvis-cai wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
elvis-cai:fix/anthropic-vertex-thinking-signature-error

Conversation

@elvis-cai

Copy link
Copy Markdown

Summary

  • 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

Test Plan

  • Added new test test_is_anthropic_invalid_thinking_signature_error_vertex_ai with the Vertex AI error format
  • All 3 related tests pass (positive, vertex_ai, negative)

Fixes #26005

…or 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 BerriAI#26005
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR relaxes the is_anthropic_invalid_thinking_signature_error detector by dropping the \"block\" keyword requirement, enabling it to also match the Vertex AI error format (\"messages.N.content.M.thinking.signature.str: Input should be a valid string\") that doesn't include the word "block". A dedicated positive test for the Vertex AI format is added alongside the existing positive and negative tests.

Confidence Score: 5/5

Safe to merge — a one-line logic relaxation with a matching new test and no regressions to existing coverage.

All findings are P2 (test coverage suggestion). The functional change is minimal and correct, no existing tests are weakened, and no real network calls are introduced.

No files require special attention.

Important Files Changed

Filename Overview
litellm/llms/anthropic/common_utils.py Removes the "block" keyword requirement from the thinking-signature error detector, allowing it to match the Vertex AI error format that omits the word "block"
tests/test_litellm/llms/anthropic/test_anthropic_common_utils.py Adds a new positive test for the Vertex AI error format; existing positive and negative tests are preserved and unmodified

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[error_text received] --> B{empty?}
    B -- yes --> C[return False]
    B -- no --> D[lowercase error_text]
    D --> E{"'invalid' in lower?"}
    E -- no --> C
    E -- yes --> F{"'signature' in lower?"}
    F -- no --> C
    F -- yes --> G{"'thinking' in lower?"}
    G -- no --> C
    G -- yes --> H[return True: self-heal strip thinking blocks and retry]
    style H fill:#d4edda,stroke:#28a745
    style C fill:#f8d7da,stroke:#dc3545
Loading

Comments Outside Diff (1)

  1. tests/test_litellm/llms/anthropic/test_anthropic_common_utils.py, line 1170-1179 (link)

    P2 Negative test doesn't cover relaxed condition

    With the removal of the "block" guard, "invalid" is now satisfied by the "invalid_request_error" error-type string rather than the human-readable message text. The existing negative tests only check empty input and a completely unrelated error string — neither exercises the scenario where a real invalid_request_error contains "thinking" and "signature" in a non-thinking-block context. Adding one targeted negative case would confirm the triple-match is tight enough to avoid false positives.

Reviews (1): Last reviewed commit: "fix(anthropic): detect invalid thinking ..." | Re-trigger Greptile

@codecov

codecov Bot commented Apr 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@elvis-cai

Copy link
Copy Markdown
Author

please help review @ishaan-berri , thanks

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions Bot added the stale label Jul 21, 2026
@github-actions github-actions Bot closed this Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: complexity router not working for claude code after auto model switching from GLM-5 to Anthropic models

2 participants