Inferensys

Prompt

CJK Language Disambiguation Prompt

A practical prompt playbook for using the CJK Language Disambiguation Prompt in production AI workflows to route Chinese, Japanese, and Korean text to the correct downstream models.
ML engineer managing model versions on laptop, version history visible, technical Git-like workflow.
PROMPT PLAYBOOK

When to Use This Prompt

Define the job, reader, and constraints for the CJK Language Disambiguation Prompt.

This prompt is for platform engineers and AI infrastructure teams who need to route Chinese, Japanese, and Korean (CJK) text to the correct downstream model, translation layer, or locale-specific workflow. The core job is reliable language identification when input text shares the CJK Unified Ideographs block—where the same Unicode character can represent a different word in each language. Use this prompt when your system ingests user-generated content, documents, or queries that may arrive without explicit language metadata, and where misrouting to the wrong language model produces garbled translations, broken search results, or degraded user trust.

The ideal scenario is a text sample of at least 15–20 characters. At this length, character frequency distributions, kana presence (Japanese), Hangul syllable blocks (Korean), and vocabulary markers provide enough signal for reliable disambiguation. The prompt is designed to work as a classification step in a routing middleware pipeline: it takes raw text and returns a language label, a confidence score, and an ambiguity flag. Do not use this prompt for single-character inputs, proper nouns in isolation, or text that consists entirely of shared CJK characters with no language-specific scripts present—these cases require a fallback to user prompting, metadata inspection, or a default routing policy. Also avoid using this prompt as a standalone translation or transliteration tool; its job is classification only.

Before wiring this into production, test it against your hardest cases: short strings under 10 characters, mixed CJK documents where Japanese text contains kanji without kana, and Korean text that uses Hanja (Chinese characters) without Hangul. These edge cases are where disambiguation confidence drops fastest. The playbook includes eval checks and failure mode guidance so you can measure misrouting rates before deployment. If your pipeline handles regulated content or high-stakes routing decisions, pair this prompt with a confidence threshold that triggers human review or a clarification request when the model cannot disambiguate reliably.

PRACTICAL GUARDRAILS

Use Case Fit

Where this prompt works, where it fails, and the operational boundaries you need before wiring it into a production CJK routing pipeline.

01

Good Fit: Long-Form Monolingual Text

Use when: inputs exceed 50 characters and contain a single predominant CJK language. Longer text provides sufficient character frequency, kana, and vocabulary signals for high-confidence disambiguation. Guardrail: Set a minimum character threshold (e.g., 50 chars) before invoking this prompt; route shorter strings to a dedicated short-text classifier.

02

Bad Fit: Mixed-CJK Documents

Avoid when: a single document contains substantial Chinese, Japanese, and Korean text simultaneously (e.g., multilingual product manuals, academic papers with mixed citations). The prompt will identify a primary language but miss secondary content that needs separate routing. Guardrail: Pre-process with a script detection step; if multiple CJK scripts are detected, split the document by script block before language disambiguation.

03

Required Inputs

What you must provide: raw text string, expected output schema (language code + confidence score), and a list of supported CJK language codes. Optional but recommended: character minimum threshold and a fallback language for ambiguous cases. Guardrail: Validate that the input is not empty, not purely numeric, and not solely Latin-script before sending to the model to avoid wasted inference.

04

Operational Risk: Short String Ambiguity

What to watch: single characters, names, or short phrases under 20 characters often fail because individual kanji/hanzi are shared across Chinese and Japanese. The model may default to the most common language in its training data rather than the correct one. Guardrail: For inputs under 20 characters, return a low-confidence flag and route to a human review queue or a secondary classifier that uses user locale metadata.

05

Operational Risk: Kana-Only Japanese vs. Chinese Hanzi

What to watch: Japanese text written entirely in hiragana or katakana is trivially identifiable, but Japanese text that happens to contain only kanji (no kana) can be misclassified as Chinese. This occurs in formal titles, names, and historical text. Guardrail: Add a post-classification check: if the predicted language is Chinese but the input contains no Chinese-specific particles or grammar patterns, flag for review and consider user metadata (e.g., browser locale) as a tiebreaker.

06

Operational Risk: Korean Hangul with Hanja

What to watch: modern Korean rarely uses hanja, but legal documents, academic texts, and names may mix hangul and hanja. The presence of hanja can pull the classifier toward Chinese if hangul proportion is low. Guardrail: Prioritize hangul detection as the strongest Korean signal. If any hangul is present, weight it heavily in the classification logic. For mixed-script inputs, run script proportion analysis before language disambiguation.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A reusable prompt template for disambiguating Chinese, Japanese, and Korean text using character-level and vocabulary-level signals.

This template is designed to be dropped directly into your CJK routing middleware. It accepts raw text and returns a structured language classification with a confidence score. The prompt uses multiple disambiguation signals—Unicode block analysis for Hangul and Kana, character frequency heuristics for Hanzi/Kanji dominance, and vocabulary marker detection—rather than relying on a single fragile signal. This multi-signal approach is essential because short strings, mixed-script documents, and proper nouns frequently defeat single-signal classifiers.

Below is the copy-ready template. Replace each square-bracket placeholder with your application's values before use. The [INPUT] placeholder receives the raw text to classify. [OUTPUT_SCHEMA] should be replaced with your expected JSON structure, typically including language, confidence, signals_used, and ambiguity_flag fields. [CONSTRAINTS] allows you to inject domain-specific rules, such as defaulting to a specific language when confidence is below threshold or handling mixed CJK documents with a primary-language extraction policy. [EXAMPLES] should contain 3–5 few-shot examples covering the hardest cases for your domain: short queries, mixed-script inputs, and proper nouns that could belong to multiple languages.

text
You are a CJK language classifier. Your task is to determine whether the input text is Chinese (zh), Japanese (ja), or Korean (ko).

Use the following signals in order of reliability:
1. **Hangul presence (U+AC00–U+D7AF)**: Any Hangul syllable blocks strongly indicate Korean.
2. **Kana presence (U+3040–U+309F Hiragana, U+30A0–U+30FF Katakana)**: Any Kana characters strongly indicate Japanese.
3. **Hanzi/Kanji character frequency**: When only CJK Unified Ideographs (U+4E00–U+9FFF) are present, compare character frequency patterns. Chinese uses a wider distribution of characters; Japanese uses a smaller set of Joyo Kanji with higher repetition.
4. **Vocabulary markers**: Detect language-specific particles, verb endings, and common words:
   - Japanese markers: は (wa), が (ga), を (wo), です (desu), ます (masu), いる/ある
   - Korean markers: 은/는 (eun/neun), 이/가 (i/ga), 을/를 (eul/reul), 합니다 (hamnida), 습니다 (seumnida)
   - Chinese markers: 的 (de), 了 (le), 是 (shi), 在 (zai), 和 (he)
5. **Script mixture patterns**: Japanese commonly mixes Kanji + Kana. Korean commonly mixes Hangul + Hanja (rare in modern text). Chinese is predominantly Hanzi with Latin script or punctuation.

[CONSTRAINTS]

Classify the following text:

[INPUT]

Return your classification in this exact JSON format:
[OUTPUT_SCHEMA]

Examples:
[EXAMPLES]

When adapting this template, pay close attention to the [CONSTRAINTS] section. For production routing, you should specify a confidence threshold below which the input is flagged for human review or routed to a fallback multilingual model. For short-text applications like search queries or chatbot messages, add an explicit instruction that inputs under 10 characters should return ambiguity_flag: true and a lower confidence score. If your system handles mixed CJK documents (e.g., a Japanese academic paper quoting Chinese text), add a constraint for primary-language extraction rather than single-language classification. The [EXAMPLES] few-shot block is not optional for this prompt—CJK disambiguation on short or ambiguous strings improves significantly with 3–5 well-chosen examples that demonstrate edge cases your application actually encounters.

After copying this template, validate it against your eval suite before deployment. Test specifically on: single-character inputs, proper nouns (person names, place names that could be Chinese or Japanese), mixed-script documents, and inputs where the only CJK characters are shared Hanzi/Kanji. These four categories produce the majority of production misclassifications. If your eval results show confidence scores clustering near your threshold, consider adding a clarification step rather than routing on low-confidence output.

IMPLEMENTATION TABLE

Prompt Variables

Required and optional inputs for the CJK Language Disambiguation Prompt. Each variable must be validated before the prompt is assembled to prevent silent misrouting on short or mixed-script inputs.

PlaceholderPurposeExampleValidation Notes

[INPUT_TEXT]

Raw text to classify as Chinese, Japanese, Korean, or mixed/ambiguous

私は日本語を勉強しています

Required. Must be non-null string. Reject empty or whitespace-only inputs. Length under 10 characters triggers low-confidence path.

[POSSIBLE_LANGUAGES]

Subset of CJK languages to consider, reducing the classification space

["ja", "zh", "ko"]

Optional array of ISO 639-1 codes. Defaults to ["zh", "ja", "ko"] if omitted. Invalid codes must be rejected at assembly time.

[CONFIDENCE_THRESHOLD]

Minimum confidence score required before routing without clarification

0.85

Float between 0.0 and 1.0. Values below 0.70 produce excessive ambiguity flags. Default 0.80 if not specified. Validate range before prompt assembly.

[SHORT_TEXT_FLAG]

Explicit signal that input is under 20 characters, triggering conservative disambiguation logic

Boolean. Set automatically by pre-prompt length check. When true, prompt should request explicit uncertainty language in output.

[MIXED_SCRIPT_POLICY]

Instruction for handling inputs containing characters from multiple CJK scripts

"flag_and_list"

Enum: "flag_and_list", "primary_only", "reject". Controls whether prompt returns all detected scripts or only the dominant one. Validate against allowed values.

[OUTPUT_SCHEMA]

Expected JSON structure for the classification result

{"primary_language": "ja", "confidence": 0.92, "detected_scripts": ["Hiragana", "Kanji"], "ambiguity_flag": false}

Required. Must include primary_language, confidence, detected_scripts, and ambiguity_flag fields. Schema mismatch at parse time triggers repair retry.

[KANA_WEIGHT]

Relative weight given to kana character presence for Japanese detection

0.40

Float between 0.0 and 1.0. Higher values prioritize hiragana/katakana signals. Default 0.35. Tune based on false-positive rate on Chinese text containing rare kana-like characters.

[HANGUL_WEIGHT]

Relative weight given to Hangul syllable blocks for Korean detection

0.50

Float between 0.0 and 1.0. Hangul is highly discriminative; default 0.50 reflects strong signal. Lower only if pipeline sees significant Hangul-in-Chinese edge cases.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the CJK disambiguation prompt into a production routing middleware with validation, retries, and fallback logic.

The CJK Language Disambiguation Prompt is designed to sit at the ingress layer of a multilingual AI platform, immediately after text ingestion and before any downstream model selection, translation, or locale-specific processing. Its job is narrow: given a raw string that may contain Chinese, Japanese, Korean, or mixed CJK text, return a single primary language label and a confidence score. This prompt is not a general language detector—it assumes the input is already known to be CJK-dominant and focuses on resolving the ambiguity that generic language classifiers struggle with. Wire it as a synchronous pre-processing step with a strict timeout (200-500ms) and a hard fallback to a script-based heuristic if the model call fails or times out.

The implementation should wrap the prompt in a lightweight router function that handles validation, retries, and logging. On invocation, construct the prompt by injecting the raw text into the [INPUT] placeholder. Set [CONSTRAINTS] to enforce a JSON-only output with fields language (one of zh, ja, ko, mixed) and confidence (0.0-1.0). After receiving the model response, validate the JSON structure and field values before acting on the result. If confidence is below a configurable threshold (start with 0.7 and tune from production logs), route to a human review queue or apply a conservative fallback policy. Log every disambiguation decision with the input hash, detected language, confidence, model used, and latency for later eval analysis. For high-throughput pipelines, batch up to 25 short strings per call to amortize latency, but keep individual string length under 500 characters to avoid token waste on long documents where CJK disambiguation is rarely the bottleneck.

Model choice matters here. Use a fast, instruction-tuned model with strong multilingual performance—Claude 3.5 Haiku or GPT-4o-mini work well for this task because the prompt relies on character-level pattern recognition (kana presence, hangul blocks, simplified vs. traditional character frequency) rather than deep semantic reasoning. Avoid larger models unless you observe persistent failures on short strings or mixed-script documents. Implement a two-tier fallback: if the primary model call fails, retry once with a different model; if both fail, fall back to a deterministic script-detection function that checks for Unicode ranges (Hangul → ko, Hiragana/Katakana → ja, CJK Unified Ideographs only → zh with low confidence). This ensures the routing pipeline never blocks on language detection failure. Wire structured logging to capture which fallback path was used so you can measure the reliability of the prompt-based path over time.

Testing this prompt in production requires a focused eval harness. Build a golden dataset of at least 200 examples covering: short strings under 10 characters (where disambiguation is hardest), mixed CJK documents (e.g., Japanese text with Chinese proper nouns), Korean text with Hanja, and edge cases like CJK punctuation-only strings or emoji-heavy inputs. Run this dataset through the prompt on every change and assert that accuracy stays above 95% for unambiguous inputs and that mixed is correctly flagged when multiple CJK languages appear. Monitor production for confidence-score calibration drift—if the model starts returning 0.99 confidence on wrong answers, you have a silent failure mode that script-based fallbacks won't catch. Set up an eval pipeline that samples production inputs weekly, runs them through the prompt, and compares against human-verified labels to detect drift before users notice.

IMPLEMENTATION TABLE

Expected Output Contract

Define the exact shape of the CJK disambiguation output so downstream routing logic can consume it deterministically. Each field must be validated before the classification result is trusted for model dispatch or queue assignment.

Field or ElementType or FormatRequiredValidation Rule

primary_language

ISO 639-1 string (zh, ja, ko)

Must be one of zh, ja, ko. Reject any other value. If confidence is below threshold, set to null and set ambiguous to true.

confidence_score

float (0.0-1.0)

Must be a number between 0.0 and 1.0 inclusive. Parse check: reject non-numeric values. If score < 0.7, set ambiguous to true and primary_language to null.

ambiguous

boolean

Must be true or false. Set to true when confidence_score < 0.7, multiple scripts detected with conflicting signals, or input length < 5 characters.

detected_scripts

array of ISO 15924 strings

Must be a JSON array. Each element must be a valid ISO 15924 code. Minimum 1 element. Common values: Hani, Hira, Kana, Hang, Latn. Reject if array is empty.

script_evidence

object mapping script code to character count

Keys must match detected_scripts. Values must be positive integers. Sum of all values must equal total character count of input. Parse check: reject negative counts.

kana_present

boolean

Must be true if Hira or Kana scripts detected. Strong signal for Japanese. If true and Hangul also present, flag for human review.

hangul_present

boolean

Must be true if Hang script detected. Strong signal for Korean. If true and kana_present also true, set ambiguous to true and primary_language to null.

vocabulary_markers

array of strings

List of CJK-specific function words or particles detected. Examples: は, が, を for Japanese; 的, 了, 是 for Chinese; 은, 는, 이, 가 for Korean. Null allowed if no markers found.

PRACTICAL GUARDRAILS

Common Failure Modes

CJK disambiguation fails silently and often. These are the most common production failure patterns and the specific checks that catch them before they cause downstream routing errors.

01

Short-String Ambiguity Collapse

What to watch: Inputs under 10 characters lack enough signal for reliable CJK disambiguation. Single-character queries, names, or hashtags default to the most common language in training data rather than the correct one. Guardrail: Implement a minimum-length threshold. For inputs below 15 characters, return a low-confidence flag and route to a clarification prompt or a unified CJK handler instead of forcing a single-language decision.

02

Mixed-CJK Document Misclassification

What to watch: Documents containing both Japanese and Chinese text—common in technical manuals, historical texts, or multilingual websites—are classified as a single language. The prompt latches onto the dominant script and ignores secondary language segments. Guardrail: Segment the input by script blocks before classification. Run disambiguation per segment and return a language map with span annotations rather than a single label. Flag inputs where multiple CJK languages exceed a 10% presence threshold.

03

Kana and Hangul Over-Indexing

What to watch: The prompt relies too heavily on kana presence for Japanese and Hangul for Korean, missing edge cases like Japanese text that is entirely kanji or Korean text written in hanja. This produces false Chinese classifications for script-only inputs. Guardrail: Add explicit fallback logic. If kana is absent but vocabulary markers suggest Japanese, or Hangul is absent but grammatical particles suggest Korean, apply secondary vocabulary-based disambiguation. Test with pure-kanji Japanese and pure-hanja Korean samples.

04

Proper Noun and Named Entity Confusion

What to watch: Chinese, Japanese, and Korean personal names, place names, and company names share character sets and produce false matches. A Japanese company name written in kanji is classified as Chinese because character frequency alone is insufficient. Guardrail: Maintain a configurable entity override list for known names. When an input is dominated by a known entity, use the entity's language label. For unknown names, flag as ambiguous and route to a locale-aware entity resolver rather than relying on character statistics.

05

Training Data Language Bias

What to watch: The model defaults to Chinese for ambiguous CJK inputs because Chinese text dominates most training corpora. This creates a systematic bias that undercounts Japanese and Korean in production traffic, especially for short or noisy inputs. Guardrail: Calibrate classification thresholds per language. Set a higher confidence bar for Chinese classification and a lower bar for Japanese and Korean. Monitor production language distributions against expected traffic patterns and alert on drift that suggests bias amplification.

06

Code-Switched CJK with Latin Script

What to watch: Inputs mixing CJK characters with Latin script—common in technical documentation, brand names, and social media—confuse script-based detection. The Latin segments are ignored, and the CJK segment is classified without considering the full context. Guardrail: Extract and classify CJK spans separately from Latin spans. Use the Latin context as a supporting signal: English loanwords suggest Japanese, English technical terms suggest Korean, and pinyin suggests Chinese. Return a composite language profile rather than a single label.

IMPLEMENTATION TABLE

Evaluation Rubric

Criteria for testing CJK disambiguation output quality before shipping. Use these checks to validate that the prompt correctly distinguishes Chinese, Japanese, and Korean text, especially for short strings and mixed-script inputs where disambiguation is hardest.

CriterionPass StandardFailure SignalTest Method

Kana detection for Japanese

Any hiragana or katakana present must classify as Japanese with confidence >= 0.95

Japanese text with kana classified as Chinese or Korean

Test set of 50 Japanese strings containing kana; measure false non-Japanese rate

Hangul detection for Korean

Any Hangul syllables (U+AC00-U+D7AF) must classify as Korean with confidence >= 0.95

Korean text with Hangul classified as Chinese or Japanese

Test set of 50 Korean strings containing Hangul; measure false non-Korean rate

Hanzi-only short string disambiguation

Chinese-only short strings (<=10 chars, no kana/hangul) classified as Chinese with confidence >= 0.70

Short Chinese text misclassified as Japanese or Korean

Test set of 100 short Chinese strings; measure accuracy and mean confidence

Kanji-only short string disambiguation

Japanese kanji-only short strings (<=10 chars, no kana) classified as Japanese with confidence >= 0.60

Short Japanese kanji text misclassified as Chinese

Test set of 50 short Japanese kanji-only strings; measure accuracy

Mixed CJK document handling

Document with >=80% Chinese characters and no kana/hangul classified as Chinese; document with mixed kanji+kana classified as Japanese

Mixed-script document assigned wrong primary language

Test set of 20 mixed CJK documents with known ground truth; measure primary language accuracy

Confidence calibration on ambiguous input

Confidence score drops below 0.60 when input is genuinely ambiguous (e.g., single shared character)

High confidence (>0.80) on single-character inputs shared across CJK

Test set of 30 single-character inputs shared across CJK; verify mean confidence < 0.60

Output schema compliance

Every response includes language_code, confidence_score, and detected_scripts fields in valid JSON

Missing fields, malformed JSON, or extra text outside schema

Schema validation on 200 responses; measure schema compliance rate

Shortest input handling

Empty or whitespace-only input returns null language_code and confidence 0.0 without error

Exception, hallucinated language, or confidence > 0.0 on empty input

Test set of 10 empty/whitespace inputs; verify null output and zero confidence

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Start with the base prompt and a simple script that sends [INPUT_TEXT] and reads the detected_language field. Use a small hand-labeled set of 20–30 examples covering Chinese, Japanese, Korean, and mixed-script edge cases. Log every response for manual review.

code
System: [BASE_CJK_DISAMBIGUATION_PROMPT]
User: [INPUT_TEXT]

Watch for

  • Over-reliance on a single signal (e.g., kana presence alone for Japanese)
  • Short strings under 10 characters where disambiguation is guesswork
  • Mixed CJK documents where the model picks one language and ignores the rest
  • No confidence score, making it impossible to set a routing threshold later
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.