BerriAI/litellm · error · ValueError

weights must sum to 1.0, got quality={q} + cost={v} = {q + v

Error message

weights must sum to 1.0, got quality={q} + cost={v} = {q + v}

What it means

Field validator on AdaptiveRouterWeights.cost: quality + cost must equal 1.0 within a 0.001 tolerance. The supplied weights sum to something else, so the adaptive router cannot interpret them as a trade-off split and validation fails.

Source

Thrown at litellm/types/router.py:980

    CODE_GENERATION = "code_generation"
    CODE_UNDERSTANDING = "code_understanding"
    TECHNICAL_DESIGN = "technical_design"
    ANALYTICAL_REASONING = "analytical_reasoning"
    WRITING = "writing"
    FACTUAL_LOOKUP = "factual_lookup"
    GENERAL = "general"


class AdaptiveRouterWeights(BaseModel):
    quality: float = Field(default=0.7, ge=0.0, le=1.0)
    cost: float = Field(default=0.3, ge=0.0, le=1.0)

    @field_validator("cost")
    @classmethod
    def _weights_sum_to_one(cls, v, info):
        q: Final = info.data.get("quality", 0.7)
        if abs(q + v - 1.0) > 0.001:
            raise ValueError(f"weights must sum to 1.0, got quality={q} + cost={v} = {q + v}")
        return v


class AdaptiveRouterConfig(BaseModel):
    available_models: list[str]
    weights: AdaptiveRouterWeights = Field(default_factory=AdaptiveRouterWeights)


class AdaptiveRouterPreferences(BaseModel):
    """model_info.adaptive_router_preferences — declared by each model."""

    model_config = ConfigDict(use_enum_values=False)

    quality_tier: int = Field(ge=1, le=3)
    strengths: list[RequestType] = Field(default_factory=list)

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Adjust quality and cost weights so they sum to 1.0 (e.g. quality=0.7, cost=0.3).
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/types/router.py:980 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/baa0b6bae82df503. Report an issue: GitHub.