From fbbebf5044d00e24c29a7e9841cf1f0ff4bc025a Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 29 Jul 2026 07:26:16 +0000 Subject: [PATCH] refactor(anthropic): drop getattr and trim docstrings in max_tokens truncation helper --- .../experimental_pass_through/adapters/handler.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py b/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py index f98eea3c562..5977f462080 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/handler.py @@ -44,18 +44,14 @@ _OUTPUT_TOKEN_LIMIT_ERROR_MARKER = "max_tokens or model output limit was reached def _is_output_token_limit_error(exc: Exception) -> bool: - """True for the provider 400 raised when the output-token budget is too - small to finish even one token (e.g. OpenAI GPT-5.x with ``max_tokens=1``).""" + """True for the provider 400 raised when the output-token budget cannot finish even one token (e.g. OpenAI GPT-5.x with ``max_tokens=1``).""" if not isinstance(exc, litellm.BadRequestError): return False - message = getattr(exc, "message", None) or str(exc) - return _OUTPUT_TOKEN_LIMIT_ERROR_MARKER in message.lower() + return _OUTPUT_TOKEN_LIMIT_ERROR_MARKER in exc.message.lower() def _build_max_tokens_truncation_response(model: str) -> ModelResponse: - """Synthesize an empty ``finish_reason="length"`` response so the empty, - ``max_tokens``-truncated turn flows through the same translation path as a - real completion (mapping to Anthropic ``stop_reason="max_tokens"``).""" + """Synthesize an empty ``finish_reason="length"`` response so the truncated turn reuses the existing translation path (mapping to Anthropic ``stop_reason="max_tokens"``).""" return ModelResponse( model=model, choices=[