BerriAI/litellm · error · ValueError

Invalid environment: . Please use one of the following…

Error message

Invalid environment: {environment}. Please use one of the following instead: {valid_values}

What it means

validate_environment (litellm/integrations/deepeval/utils.py) checks LITELM_ENVIRONMENT against the Environment enum, whose only members are "production", "development", "staging" (default is "development" when unset). The comparison is exact and case-sensitive, so "prod", "dev", "PRODUCTION", or any custom string raises ValueError during DeepEvalLogger initialization.

Solutions

  1. Use exactly one of: production, development, staging (lowercase)
  2. Unset LITELM_ENVIRONMENT to fall back to the development default
  3. Map your internal value before it reaches litellm: LITELM_ENVIRONMENT=$(case "$STAGE" in prod) echo production;; *) echo development;; esac

Example fix

# before
export LITELM_ENVIRONMENT=prod   # ValueError

# after
export LITELM_ENVIRONMENT=production
Defensive patterns

Strategy: validation

Validate before calling

VALID = {"production", "development", "staging"}

def litellm_environment_ok() -> bool:
    import os
    return os.getenv("LITELM_ENVIRONMENT", "development") in VALID

def normalize_env(value: str | None) -> str:
    aliases = {"prod": "production", "dev": "development", "stage": "staging"}
    v = (value or "development").lower()
    return aliases.get(v, v)

Type guard

from typing import Any

def is_valid_environment(value: Any) -> bool:
    """Exact, case-sensitive membership in litellm's Environment enum."""
    return value in ("production", "development", "staging")

Prevention

When it happens

Trigger: Setting LITELM_ENVIRONMENT=prod (common alias) instead of production; capitalized values like Staging; pipeline-injected values such as "pr-123" or "qa" that don't match the enum; empty-string value also fails the membership test.

Common situations: Organizations whose existing DEPLOYMENT_ENV/ENV conventions use prod/dev/qa; CI injecting branch names as environment; case mismatches from copy-pasting docs.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/9a4074747fea2d39. Report an issue: GitHub.

Appendix: source

Thrown at litellm/integrations/deepeval/utils.py:14

from datetime import datetime, timezone
from typing import Final

from litellm.integrations.deepeval.types import Environment


def to_zod_compatible_iso(dt: datetime) -> str:
    return dt.astimezone(timezone.utc).isoformat(timespec="milliseconds").replace("+00:00", "Z")


def validate_environment(environment: str):
    if environment not in [env.value for env in Environment]:
        valid_values: Final = ", ".join(f'"{env.value}"' for env in Environment)
        raise ValueError(f"Invalid environment: {environment}. Please use one of the following instead: {valid_values}")

View on GitHub (pinned to 77b7c6c40c)