Detect the language(s) of a text from a closed set of 41 ISO 639-1 codes — handles short snippets, code-mixed, and transliterated text, with per-language confidence.
Detect the language(s) of a text from a closed set of 41 ISO 639-1 codes (plus "und" for genuinely undetermined input). Handles the cases that break n-gram detectors: short snippets, code-mixed text (Hinglish, Spanglish), and transliterated text — romaji is ja, pinyin is zh, "privet, kak dela" is ru. Judge by the language, not the script.
Use it to route incoming messages to the right support queue or translation pipeline (pair with text-translation), to tag user-generated content, or to pick the source language before batch localization.
| Entrypoint | Renders | Inputs |
|---|---|---|
system | Detection rules + the supported-code list + embedded output schema | — |
user | The delimited text block | text |
Render system as the system message and user as the user message.
text (string, required) — the text to identify. May be short, code-mixed, transliterated, or empty.{
"reasoning": "Latin script with Devanagari-origin vocabulary and Hindi grammar carrying the sentence; English tech terms mixed in.",
"primary_language": "hi",
"confidence": 0.85,
"other_languages": [{ "language": "en", "confidence": 0.9 }]
}
primary_language is a closed enum — your switch statement can be exhaustive. parseOutput() guarantees you never see a code you didn't plan for.confidence is an uncalibrated heuristic, not a probability: long unambiguous text scores high, a two-word snippet scores lower, "und" is capped at 0.2.other_languages lists genuinely-present other languages (whole words/phrases — borrowed words like "hotel" and proper nouns don't count), ordered by prominence, never duplicating the primary."und" is for no-language input — empty text, numbers/emoji, character noise — not for "short". "merci beaucoup" is fr.en."und" + confidence ≤ 0.2 + empty other_languages.primary_language == case.expected_language over a published dataset — no judge needed.additionalProperties: false.<text> delimiter.Part of the Translation Essentials collection.