langgenius/dify · error · ValueError
{lang} is not a valid language.
Error message
{lang} is not a valid language. What it means
Raised by supported_language(lang) when lang is not a key in language_timezone_mapping. The supported set is the 23 locale codes in api/constants/languages.py (en-US, zh-Hans, zh-Hant, pt-BR, es-ES, fr-FR, de-DE, ja-JP, ko-KR, ru-RU, it-IT, uk-UA, vi-VN, ro-RO, pl-PL, hi-IN, tr-TR, fa-IR, sl-SI, th-TH, id-ID, ar-TN, nl-NL).
Source
Thrown at api/constants/languages.py:35
"hi-IN": "Asia/Kolkata",
"tr-TR": "Europe/Istanbul",
"fa-IR": "Asia/Tehran",
"sl-SI": "Europe/Ljubljana",
"th-TH": "Asia/Bangkok",
"id-ID": "Asia/Jakarta",
"ar-TN": "Africa/Tunis",
"nl-NL": "Europe/Amsterdam",
}
languages = list(language_timezone_mapping.keys())
def supported_language(lang):
if lang in languages:
return lang
error = f"{lang} is not a valid language."
raise ValueError(error)
def get_valid_language(lang: str | None) -> str:
if lang and lang in languages:
return lang
return languages[0]
View on GitHub (pinned to ef8544b173)
Solutions
- Pass one of the supported locale codes (e.g. 'en-US', 'zh-Hans').
- Map bare codes to a supported default, or use get_valid_language which falls back instead of raising.
- Normalize underscores to hyphens and append a region if missing.
Example fix
// before
supported_language('en')
// after
from constants.languages import get_valid_language
lang = get_valid_language('en') # falls back to en-US
// or pass an exact supported code:
supported_language('en-US') Defensive patterns
Strategy: validation
Validate before calling
from constants.languages import languages
def is_supported_language(lang: str | None) -> bool:
return lang in languages Type guard
from constants.languages import languages
def is_supported_language(lang: str | None) -> bool:
return isinstance(lang, str) and lang in languages Prevention
- Prefer get_valid_language for untrusted input — it falls back instead of raising.
- Normalize browser locale codes (underscore -> hyphen) before calling supported_language.
- Keep a whitelist aligned with language_timezone_mapping keys.
When it happens
Trigger: Calling supported_language('en') (missing region), 'en_US' (underscore vs hyphen), or any unsupported locale such as 'de' or 'zh'.
Common situations: Browser locale negotiation yielding a bare language code, an Accept-Language header mapped naively, or hardcoded locale strings that differ from the supported keys.
Related errors
- streaming response body missing
- usage_missing_arg
- usage_missing_arg
- usage_invalid_flag
- expected integer, got ${JSON.stringify(raw)}
AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12).
Data as JSON: /api/errors/71c00f61571f28ad.
Report an issue: GitHub.