feat: add --label-language flag and GRAPHIFY_LABEL_LANGUAGE env var for LLM community labels
Fixes #1824
Problem
The prompt in _label_batch_with_retry (llm.py) was a hardcoded English
string with no language directive. Since the LLM inferred output language
ambientlyfrom sampled node labels, the same community could be named in
English in one relabel pass and in the team's natural language in another.
This made diffing labels across reclusters noisy and forced manual
normalization for non-English teams.
Solution
Added an explicit language instruction to the labeling prompt, controllable via:
--label-languageflag on bothgraphify labelandgraphify cluster-onlyGRAPHIFY_LABEL_LANGUAGEenvironment variable as a fallback
When neither is set, behavior is identical to before (no language directive in the prompt), so this is fully backward compatible.
Changes
graphify/llm.py
- Added
label_language: str | None = Noneparameter to_label_batch_with_retry,label_communities, andgenerate_community_labels - Injected
_lang_clauseinto the labeling prompt when a language is specified, e.g." Respond in Portuguese." - Reads
GRAPHIFY_LABEL_LANGUAGEenv var as fallback when no explicit value is passed - Threaded
label_languagethrough recursive retry calls so it is not lost on batch splits
graphify/cli.py
- Added
--label-languageargument parsing (supports both--label-language Portugueseand--label-language=Portugueseforms) to the sharedcluster-only/labelhandler - Passed
label_languagethrough togenerate_community_labels
Usage
# CLI flag
graphify label --label-language Portuguese
graphify cluster-only . --label-language Japanese
# Environment variable
GRAPHIFY_LABEL_LANGUAGE=French graphify label
Backward Compatibility
No breaking changes. When --label-language is not set and
GRAPHIFY_LABEL_LANGUAGE is unset, the prompt is identical to before.