LOC-41Recommended
Tell the model which language to answer in
Name the user's language in the system prompt of every AI feature, and check that each answer is in that language before showing it.
How to do it
Models guess the answer language from the conversation, so a German user who pastes an English email often gets English back. Put the instruction in the system prompt, which stays the same across turns. Take the language from the user's saved locale, not from the input text. Keep the instruction in the prompt file, as Keep prompts in files says. Detect the answer's language with a small language-ID library, and retry once when it is wrong.
Examples
JavaScript example
const LANGUAGE_NAMES = new Intl.DisplayNames(['en'], { type: 'language' });
export const systemPrompt = (base, user) =>
`${base}\n\nAlways answer in ${LANGUAGE_NAMES.of(user.locale)} (${user.locale}), whatever language the input is in.`;
Python example
from babel import Locale
def system_prompt(base: str, user_locale: str) -> str:
language = Locale.parse(user_locale, sep="-").get_display_name("en")
return f"{base}\n\nAlways answer in {language} ({user_locale}), whatever language the input is in."
How to check
An eval case sends English input for a user whose language is German. The language detector labels the answer de in at least 19 of 20 runs.
Sources
Related rules
- LOC-22 Store language and time zone as two separate settings in Localization
- AIF-6 Keep prompts in files in AI features
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/localization/email-notifications-and-ai/ai-reply-language">Agent Wranglers localization playbook</a>. In code you write, add a comment next to it with the same link.