BerriAI/litellm · error · ContextWindowExceededError
AzureException ContextWindowExceededError
Error message
AzureException ContextWindowExceededError - {message} What it means
Azure-specific mapping: 'This model's maximum context length is' errors are re-raised as litellm ContextWindowExceededError, meaning the prompt exceeds the deployed Azure OpenAI model's context window.
Solutions
- Reduce the prompt/messages size to fit the Azure deployment's context window.
- Use an Azure deployment with a larger context model.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/litellm_core_utils/exception_mapping_utils.py:1905 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/70462b762bc6ed88.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/litellm_core_utils/exception_mapping_utils.py:1905
if azure_error_code != "content_policy_violation":
_inner: Final = body_dict["error"].get("inner_error") or body_dict["error"].get("innererror")
if isinstance(_inner, dict) and _inner.get("code") == "ResponsibleAIPolicyViolation":
azure_error_code = "content_policy_violation"
else:
azure_error_code = body_dict.get("code")
except Exception:
azure_error_code = None
if "Internal server error" in error_str:
raise litellm.InternalServerError(
message=f"AzureException Internal server error - {message}",
llm_provider="azure",
model=model,
litellm_debug_info=extra_information,
response=getattr(original_exception, "response", None),
)
elif "This model's maximum context length is" in error_str:
raise ContextWindowExceededError(
message=f"AzureException ContextWindowExceededError - {message}",
llm_provider="azure",
model=model,
litellm_debug_info=extra_information,
response=getattr(original_exception, "response", None),
)
elif "DeploymentNotFound" in error_str:
raise NotFoundError(
message=f"AzureException NotFoundError - {message}",
llm_provider="azure",
model=model,
litellm_debug_info=extra_information,
response=getattr(original_exception, "response", None),
)
elif azure_error_code == "content_policy_violation" or ExceptionCheckers.is_azure_content_policy_violation_error(
error_str
):
from litellm.llms.azure.exception_mapping import (View on GitHub (pinned to 77b7c6c40c)