BerriAI/litellm · error · ValueError
Invalid CZRN format: {czrn}
Error message
Invalid CZRN format: {czrn} What it means
ValueError raised by CZRNGenerator.extract_components when the input string does not match the CZRN regex — fewer than six colon-separated components after 'czrn:', empty components (double colons), uppercase letters in the lowercase-only groups (service_type, region, owner_account_id, resource_type), or a missing/misspelled 'czrn:' prefix. This validates externally supplied strings; use is_valid() first to check without raising.
Source
Thrown at litellm/integrations/cloudzero/cz_resource_names.py:111
czrn: Final = f"czrn:{service_type}:{provider}:{region}:{owner_account_id}:{resource_type}:{cloud_local_id}"
if not self.is_valid(czrn):
raise ValueError(f"Generated CZRN is invalid: {czrn}")
return czrn
def is_valid(self, czrn: str) -> bool:
"""Validate a CZRN string against the standard format."""
return bool(self.CZRN_REGEX.match(czrn))
def extract_components(self, czrn: str) -> tuple[str, str, str, str, str, str]:
"""Extract all components from a CZRN.
Returns: (service_type, provider, region, owner_account_id, resource_type, cloud_local_id)
"""
match: Final = self.CZRN_REGEX.match(czrn)
if not match:
raise ValueError(f"Invalid CZRN format: {czrn}")
return cast(tuple[str, str, str, str, str, str], match.groups())
def _normalize_provider(self, provider: str) -> str:
"""Normalize provider names to standard CZRN format."""
# Map common provider names to CZRN standards
provider_map: Final = {
litellm.LlmProviders.AZURE.value: "azure",
litellm.LlmProviders.AZURE_AI.value: "azure",
litellm.LlmProviders.ANTHROPIC.value: "anthropic",
litellm.LlmProviders.BEDROCK.value: "aws",
litellm.LlmProviders.VERTEX_AI.value: "gcp",
litellm.LlmProviders.GEMINI.value: "google",
litellm.LlmProviders.COHERE.value: "cohere",
litellm.LlmProviders.HUGGINGFACE.value: "huggingface",
litellm.LlmProviders.REPLICATE.value: "replicate",
litellm.LlmProviders.TOGETHER_AI.value: "together-ai",
}View on GitHub (pinned to 77b7c6c40c)
Solutions
- Pre-check with generator.is_valid(czrn) — it returns bool instead of raising
- Only construct CZRNs via create_from_components / create_from_litellm_data so the format holds by construction
- Strip whitespace and lowercase the string before validation if the source is untrusted
- If parsing persisted CZRNs, re-generate from the original row data instead of string-munging old values
Example fix
# before
svc, prov, region, owner, rtype, local_id = gen.extract_components(user_supplied_czrn)
# after
if not gen.is_valid(user_supplied_czrn.strip().lower()):
raise ValueError(f"not a usable CZRN: {user_supplied_czrn!r}")
svc, prov, region, owner, rtype, local_id = gen.extract_components(user_supplied_czrn.strip().lower()) Defensive patterns
Strategy: type-guard
Validate before calling
czrn = czrn.strip().lower()
if not generator.is_valid(czrn):
raise ValueError(f"refusing to parse malformed CZRN: {czrn!r}") Type guard
import re
CZRN_PATTERN = re.compile(r"^czrn:([a-z0-9-]+):([a-zA-Z0-9-]+):([a-z0-9-]+):([a-z0-9-]+):([a-z0-9-]+):(.+)$")
def is_czrn(value: str) -> bool:
return isinstance(value, str) and bool(CZRN_PATTERN.match(value)) Try / catch
try:
components = generator.extract_components(czrn)
except ValueError:
# regenerate from source data instead of repairing the string
components = None Prevention
- Always gate extract_components with generator.is_valid()
- Generate CZRNs only through create_from_components — never string-format them by hand
- Avoid case-transforming persisted CZRNs downstream (several components are lowercase-only)
When it happens
Trigger: Calling extract_components on a hand-built or persisted CZRN that was never produced by create_from_components: 'czrn:litellm:openai::cross-region:...' (empty component), 'CZRN:litellm:...' (prefix), 'czrn:litellm:openai:Cross-Region:...' (uppercase region), a truncated string, or leading/trailing whitespace around the czrn.
Common situations: CZRNs written by other tooling or edited by hand; strings loaded from config/database without normalization; copy-paste truncation; case-changing transformations (e.g. upper-casing identifiers) applied downstream.
Related errors
- Generated CZRN is invalid: {czrn}
- Could not parse timestamp '{timestamp_str}': {e}
- CloudZero configuration missing. Please set CLOUDZERO_API_KE
- Database not connected. Connect a database to your proxy - h
- limit must be an integer
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/dce4090f9bbb7472.
Report an issue: GitHub.