Tutorial: Bilingual (English/Arabic) Prompts

On this page

zerda.prompt natively supports English and Modern Standard Arabic throughout the entire prompt scaffold — personas, section headers, guardrail text, and output-format instructions are all separately authored in Arabic rather than translated on the fly. See the rationale in api/templates.

1. Build an Arabic prompt

Python · 5 lines
prompt = engine.build(
    query="ما هي سياسة الإجازات؟",
    documents=hr_policy_docs,
    language="ar",
)

Any value in resolve_lang's alias set works: "ar", "arabic", "ar-eg", "ar-sa", "ar-ae", "msa", or the Arabic-script strings "فصحى", "عربي", "العربية", "مصري", "اللغة العربية". See the full list in api/templates.

2. Combine with a user profile

Python · 7 lines
prompt = engine.build(
    query="اشرح لي أسباب الأزمة المالية لعام 2008",
    documents=docs,
    language="ar",
    user_profile="academic",   # -> "استخدم لغة أكاديمية رسمية..."
    strategy="cot",
)

3. A third language (no native template)

Python
prompt = engine.build(query="Quelle est la politique de remboursement ?", documents=docs, language="fr")

Since "fr" isn't in the Arabic alias set, resolve_lang returns Lang.EN — the system prompt is built from the English templates, with one line appended: "Respond in fr." (verbatim, using whatever string you passed as language). This is a much weaker guarantee of output quality/consistency than the native EN/AR paths — treat any non-en/ar language value as "best-effort" rather than fully supported.

4. Checking support before building

Python · 4 lines
from zerda.prompt.templates import is_supported

if not is_supported(user_language):
    log.warning("Language %s has no native template; falling back.", user_language)

Related pages