A user switches your app to Korean, opens the new assistant, and asks a question in Korean. The first answer is Korean. Twenty turns later, right after the assistant reads an English tool result, the answer comes back in English. No string is missing from your catalog, and localization QA never saw the problem, because a model wrote that text at runtime.
The same drift shows up in summaries, smart replies, generated titles, and on-device helpers in localized mobile and web apps. It happens because the model is guessing the language. The fixes are to decide the language in your code, gate on-device models that support fewer languages than your app, and check each reply before a user sees it.
The short answer
- Decide the reply language in app code, from the language the user selected for your app, and store it per session.
- Send that language with every request, both in the system instructions and as a short line at the end of the context, on every turn.
- Before calling an on-device model, check that the selected locale is supported and give unsupported languages a real fallback.
- Keep app-owned text such as errors, labels, and formatted numbers out of the model, and render it from your string catalog and locale formatters.
- Detect the language of each reply, retry once on a confident mismatch, and log where the language decision came from.
Why an AI reply ends up in the wrong language
Most reports trace back to one of five causes.
The model infers the language from the context, and the context is mostly not the user. In notelore #653, an assistant answered English messages in Turkish in 3 of 8 evaluated turns. The maintainer's diagnosis was that the only text in the user's language was the message itself, while the notes, facts, and tool results were all Turkish and outweighed the single rule in the system prompt. The same pattern shows up in claude-code #106971, where a session with a Korean language setting produced English final answers after a model switch, right after long English tool output and background task notifications.
A one-time instruction weakens over a long session. The specsmith #62 report describes a language rule that fired once at session start, after which local models drifted back to another language on later turns. claude-code #105644 reports a Japanese setting that stopped holding partway through a session.
The app reads the wrong signal. In argus #378, Spanish prompts from a guest with an English browser were answered in English because the reply followed the workspace language chosen from the browser, not the message. In c55-final-project-group-A #104, the team found the model picking up the event's city, the earlier conversation, and the Accept-Language header, which they confirmed was present on every request whatever the user typed.
Language detection guesses on short or romanized text. compass-needle #60 stopped forcing a guessed language on plain English and romanized Indian-language messages when its rule-based detector was not confident.
The base model has a strong default. DeepSeek-V3 #1226, with 30 comments, reports English conversations that sometimes got a full reply in Chinese, non-deterministically. You cannot prompt your way fully out of that, which is why the last step in this guide is a check on the output.
These are author reports from individual projects, not measurements across models. In each one, the app left the reply language for the model to infer or fed it the wrong signal.
Decide the reply language in code
Anthropic's documentation on multilingual support says the model infers the response language from the conversation, but that production applications should state the target language explicitly, and that an app which lets users pick a language at runtime should put that choice into the system prompt rather than rely on inference. Apple's guide to supporting languages and locales with Foundation Models makes the same point from the other side: by default the model responds in the language of its inputs, and when your built-in prompts and the user's input are in different languages, it may respond in either or both.
So resolve the language before the call. A practical order for an app:
- The language selected for your app. On iOS this is the per-app language from Settings, which Apple notes might differ from the device's default language. On Android it is the value from per-app language preferences. If your app has its own in-app selector, use the same stored value your UI uses.
- The language of the current message, when your product wants mirroring and detection is confident. Skip this step for features that must answer in the app language, such as a support assistant inside a localized account screen.
- The last confidently detected language in this conversation. A user who wrote four messages in Spanish and then sends "ok" still wants Spanish.
- Your default language, only when there is nothing else.
The language source for an AI reply should be the app's selected language, not the browser's Accept-Language header or the device language, because per-app language settings can differ from both and the header is sent on every request regardless of what the user typed. On the web, the header describes the browser, which is often an English browser used by someone who reads Spanish. Read it once to suggest a first language, the way you would on first launch, and then use the stored choice.
type LanguageDecision = {
tag: string; // BCP 47, for example "ko" or "pt-BR"
source: "app-setting" | "message" | "conversation" | "default";
confidence?: number;
};
function resolveReplyLanguage(input: {
appLanguage?: string; // the stored in-app or per-app selection
mirrorUserLanguage: boolean; // product rule for this feature
detected?: { tag: string; confidence: number };
lastConfident?: string;
fallback: string;
}): LanguageDecision {
if (!input.mirrorUserLanguage && input.appLanguage) {
return { tag: input.appLanguage, source: "app-setting" };
}
if (input.detected && input.detected.confidence >= 0.8) {
return { tag: input.detected.tag, source: "message", confidence: input.detected.confidence };
}
if (input.lastConfident) return { tag: input.lastConfident, source: "conversation" };
if (input.appLanguage) return { tag: input.appLanguage, source: "app-setting" };
return { tag: input.fallback, source: "default" };
}
The threshold is a placeholder for a value you tune on your own messages. When a user changes the app language mid-conversation, treat it like any other in-app language change: update the stored value and use it from the next turn.
Put the language in the request every turn
Once you have a decision, send it in two places.
The first is the system instructions, written once for all languages with the language as a variable. Apple's guide suggests explicit phrasing such as "You MUST respond in Italian", and for locales other than U.S. English it recommends starting the instructions with the exact phrase "The person's locale is" followed by the locale identifier, which it says comes from the model's training and reduces hallucinations in multilingual situations. Keeping one template with a variable also keeps the shared prefix identical across users, which one guide on wrong-language replies points out matters if you rely on prompt caching.
The second is a short line at the very end of the context, after retrieved documents and tool results. That was the fix proposed in notelore #653, and it is the cheapest way to counter a context dominated by another language. Label retrieved text as source material so the model does not read it as the conversation.
function buildMessages(lang: LanguageDecision, history: Msg[], docs: string[]) {
const system =
`The person's locale is ${lang.tag}. ` +
`Write every reply in ${languageName(lang.tag)}, whatever language the ` +
`documents, tool results, or earlier messages use. Keep product names, ` +
`code, and quoted error strings unchanged.`;
return [
{ role: "system", content: system },
...history,
{ role: "user", content: "Source material:\n" + docs.join("\n---\n") },
{ role: "user", content: `Reply language: ${lang.tag}` },
];
}
Repeat this on every turn rather than only when the session starts. Long agent sessions with many tool calls are exactly where the reports above failed.
If you use Chrome's built-in Prompt API, the language is also a session option: you declare expectedInputs languages for the system prompt and user prompt, and expectedOutputs languages for the reply, and the session can throw a NotSupportedError for an unsupported input or output.
Gate on-device models by locale
On-device models support fewer languages than most localized apps, so check the app's selected locale before you call the model and design the unsupported-language path as a normal state. The wrong-language guides we opened while researching this assume a hosted model and skip this step.
Chrome's Prompt API documentation lists en, ja, es, de, and fr as accepted languages, with more in development, and tells you to pass the same options to availability() that you later use in prompt(). An app localized into 20 languages has 15 that this feature cannot serve today.
On Apple platforms, supportsLocale(_:) returns whether the model supports a locale and, by default, uses the current locale, which accounts for the person's app-specific language setting. Apple notes that language support improves in newer model and OS versions, so someone on an older OS may lack a language that a newer one has. If the input contains an unsupported language, the session throws unsupportedLanguageOrLocale. Apple also warns that guardrails apply only to supported languages, and that a short unsupported phrase mixed into supported text might not throw at all.
import FoundationModels
func assistantAvailability() -> AssistantState {
guard SystemLanguageModel.default.supportsLocale() else {
// The app is set to a language the on-device model cannot use.
return .unavailable(reason: .unsupportedLanguage)
}
return .ready
}
Decide in advance what the user sees in each unsupported language. Apple lists three options: explain that the language is not supported for this feature, disable the feature, or provide an alternative experience. A hosted model for those languages is one alternative; an honest disabled state with a localized explanation is another. Falling back to English without saying so recreates the original bug. If the feature translates user content instead of chatting, our guide to on-device translation for user-generated content covers the same availability problem for translation models.
Keep app-owned text out of the model
Everything around the generated reply is still your UI: the error when generation fails, the "Regenerate" button, the citation labels, the conversation title, the empty state. Those strings belong in your string catalog with the rest of the app, reviewed like any other copy. A small example of this going wrong is brainmatter #2, where the interface followed the selected language but the demo backend's error messages for an AI connection stayed German.
The same applies to anything you store. If the model writes a title, a category, or a status that you save and show later, the user may have switched languages by then. Store a language-neutral value, such as an enum or a key, and render the label from the catalog at display time. tetonor #30 applies a similar split for an agent workflow: replies follow the user's language, while written artifacts stay in one fixed language and a test guards the rule.
Numbers, amounts, and dates written by the model skip your locale formatters, so return them as structured values and format them in the app with the same formatter as the rest of the screen. IncarnaMind #2404 shows the failure: with the interface in Simplified Chinese, a correct, cited answer still read "2.6 million pounds" inside Chinese sentences and pasted an untranslated English quote, where the reporter expected amounts written the Chinese way. When a reply has to contain a figure, ask for structured output with the raw number and currency, then format it with Intl.NumberFormat or the platform equivalent, exactly as you would for dates, times, and numbers elsewhere in the app. For quotes from source documents, keep the original in the citation and tell the model to paraphrase in the reply language.
Check the reply before you show it
Prompts reduce drift, and the non-deterministic DeepSeek report shows they will not remove it. Add a cheap check after generation:
- Run a language detector on the reply text. Chrome's Language Detector API returns ranked candidates with a confidence between 0.0 and 1.0, and warns that very short phrases and single words give low accuracy, so it suggests returning unknown below a threshold.
- If the reply is long enough and confidently in another language, regenerate once with the reply language restated at the end.
- If the second attempt also misses, show a localized message or hand off to a person. Do not loop.
- Skip the check for very short replies such as a name or a number.
Log the decision on every turn: the chosen language, its source from the resolver above, the detector result on the input, and the detector result on the output. When a user reports "it keeps answering in English", that log line tells you whether the resolver, the prompt, or the model was wrong. A thread on the OpenAI developer forum, Model ignores user language, ends with the original poster passing the browser language, the site language, and a detector result into the system prompt; logging those inputs separately is what lets you tell them apart later.
Mirror the user or pin the app language
Projects disagree about the default. gemini-cli #1871 asked for replies in the same language as the question. qwen-code #6943 objected to the opposite design, where an output language generated from the system locale was enforced with "MUST" wording and overrode the user's input language, and asked for an automatic mode.
Pick one rule per feature and write it into the feature spec.
| Feature | Reply language rule | Why |
|---|---|---|
| Support or account assistant inside localized screens | App language | The surrounding UI, help links, and legal text are in that language |
| Open chat or writing helper | Mirror the latest message when confident, else app language | Users often write in more than one language |
| Summary or title saved to the user's data | App language at display time, stored as structured data | The user may change languages later |
| Translation feature | Explicit source and target | Anthropic's guide recommends naming both languages |
| On-device feature in an unsupported locale | No generation; localized explanation or hosted fallback | The model cannot serve that language |
Test the language behavior
Add a small matrix to your release checks for every AI feature:
- App language set to each supported language, with the device language left in English.
- A message in the app language and a message in a different language.
- Retrieved documents in a third language, and a long English tool result before the reply.
- A conversation of at least 20 turns, then an app language change mid-conversation.
- A one-word message and a romanized message.
- An app language the on-device model does not support, on the oldest OS you ship.
- A reply that must contain an amount, a date, and a quoted source sentence.
For each case, assert the detected language of the reply, the localized UI around it, and the formatted numbers. Treat failures like any other localization defect, with the same review workflow you use for translated strings.
Next step
Pick your most used AI feature and run the matrix above with the app set to a non-English language and an English device. If any reply comes back in English, add the resolver and the end-of-context language line first, then the reply check, and log the language source so the next report takes minutes to diagnose.
