BerriAI/litellm · error · AnthropicContextManagementError

context_management polyfill failed: {e}

Error message

context_management polyfill failed: {e}

What it means

Error "context_management polyfill failed: {e}" thrown in BerriAI/litellm.

Source

Thrown at litellm/llms/anthropic/experimental_pass_through/adapters/handler.py:305

        )
    except AnthropicContextManagementError:
        # Surface validation errors so the endpoint can emit an Anthropic-format
        # 400. Other exception types fall into the best-effort branch below.
        raise
    except Exception as e:
        verbose_logger.exception("context_management polyfill: skipping edits due to error: %s", e)
        # Best-effort swallow is only safe for compact-only specs, where the
        # caller's compaction-block-slicing safety net produces a correct
        # (if degraded) result. When the spec also requested non-compact
        # edits (e.g. ``clear_tool_uses_20250919``), the safety net does
        # NOT re-run those editors, so silently returning ``None`` would
        # drop them with no error surface. Raise instead so the endpoint
        # emits an Anthropic-format error.
        if _spec_has_non_compact_edits(
            context_management_spec=context_management_spec,
            additional_drop_params=additional_drop_params,
        ):
            raise AnthropicContextManagementError(
                status_code=500,
                message=f"context_management polyfill failed: {e}",
            ) from e
        return None


########################################################
# init adapter
ANTHROPIC_ADAPTER: Final = AnthropicAdapter()
########################################################


class LiteLLMMessagesToCompletionTransformationHandler:
    @staticmethod
    def _route_openai_thinking_to_responses_api_if_needed(
        completion_kwargs: _CompletionKwargs,
        *,
        thinking: Mapping[str, object] | None,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Check the context_management configuration; see the wrapped exception.

When it happens

Trigger: Thrown at litellm/llms/anthropic/experimental_pass_through/adapters/handler.py:305 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/5ed9159527d1fc61. Report an issue: GitHub.