Skip to content

Language guardrail

The language guardrail is a Tier 1 (in-process, sub-millisecond) guardrail that identifies the dominant writing system of request or response text and blocks or flags traffic that does not use a permitted script. It is suited for deployments that serve a known-language audience and need to prevent misuse through non-Latin scripts or detect unexpected language usage.

When to use the language guardrail

Use the language guardrail when your deployment serves a specific-language audience and you need to block or log requests or responses in unexpected writing systems. Note that the guardrail detects writing systems, not languages — all Latin-script languages (English, French, German, Spanish, and others) map to the same latin code.

How it works

Detection uses UTF-8 byte-range heuristics — no dictionary lookups or external models are required. Each code point is classified into one of the supported writing systems. The detected script is the non-Latin writing system with the highest character count, provided that count meets or exceeds min_ratio of all characters. When no non-Latin script meets the min_ratio threshold, the text is classified as latin.

The guardrail counts the characters of the raw request body (on the response target: the raw response body). This body is JSON, so field names, punctuation, the system prompt and earlier turns count as Latin characters too. A short non-Latin message in a long conversation can stay below min_ratio.

The language codes in allowed are case-sensitive and must be written in lower case. The block or flag reason is language:<code>, for example language:cyrillic.

Sub-Latin language discrimination

The language guardrail detects writing systems, not individual languages. All Latin-script languages map to the same latin code. It is not possible to permit English while blocking French using this guardrail. For sub-Latin language discrimination (e.g. allow only English), use a sidecar language-detect service and apply the result via a custom guardrail or routing rule.


Configuration reference

Field Type Default Description
type string — Must be "language"
name string — Human-readable label for this guardrail instance
action string "block" What to do on a disallowed script: block or flag
target string "request" Which traffic to inspect: request, response, or both
allowed array — Language codes that are permitted. Traffic using any other detected script triggers the configured action. An empty or omitted allowed list makes the detector a no-op — every request passes.
min_ratio number 0.1 Minimum fraction of non-Latin characters needed for a non-Latin script to be declared dominant. Below this threshold, the text is classified as latin.

Supported scripts

Language code Writing system Unicode range
latin Latin, ASCII, and all unclassified text, including Korean Hangul and Japanese kana Default (non-matching characters)
cjk Han characters only (Chinese characters, also used in Japanese Kanji). Korean Hangul and Japanese kana are not recognised as cjk. U+4000–U+9FFF
cyrillic Russian, Bulgarian, Serbian, Ukrainian, and others U+0400–U+04FF
arabic Arabic, Farsi, Urdu U+0600–U+06FF
hebrew Hebrew (the range also includes the last Armenian characters, U+0580–U+058F) U+0580–U+05FF
thai Thai U+0E00–U+0E7F
devanagari Hindi, Sanskrit, Marathi, Nepali, and others U+0900–U+097F

min_ratio setting

min_ratio prevents false positives on text that mixes scripts — for example, an English sentence that mentions a product name in Cyrillic or includes a few CJK characters. With the default min_ratio: 0.1, at least 10% of the text must be a given non-Latin script before it is declared dominant.

Lower min_ratio to increase sensitivity to mixed-script content. Raise it to require a more heavily non-Latin document before triggering.


Example configurations

Allow only Latin-script requests

Block any request that is predominantly written in a non-Latin writing system:

{
  "type": "language",
  "name": "latin-only",
  "action": "block",
  "target": "request",
  "allowed": ["latin"]
}

Allow Latin and CJK (for a bilingual deployment)

{
  "type": "language",
  "name": "latin-cjk",
  "action": "block",
  "target": "both",
  "allowed": ["latin", "cjk"]
}

Flag non-Latin requests for review without blocking

{
  "type": "language",
  "name": "non-latin-flag",
  "action": "flag",
  "target": "request",
  "allowed": ["latin"]
}

Increase sensitivity to mixed-script content

With min_ratio: 0.05, even a small fraction of Cyrillic characters triggers detection:

{
  "type": "language",
  "name": "strict-latin",
  "action": "block",
  "target": "request",
  "allowed": ["latin"],
  "min_ratio": 0.05
}

Configuring the language guardrail

The Guardrail Builder has no button to add a language guardrail and no editor for its type-specific settings. The builder offers buttons only for the PII protector, Presidio, Prompt Guard, Prompt Injection, regex, keyword, custom PII, and jailbreak detector types — language is configured through the gateway configuration API only, by adding a detector object to the gateway's guardrails array. A language detector added this way appears in the Guardrail Builder as a card: you can enable or disable it, reorder it, remove it, and edit its Name, Action and Target there (Target must be request, response or both). Its type-specific fields can be changed through the API only.

Proceed as follows:

  1. Build the detector as a JSON object — see Example configurations above.
  2. Add the object to the guardrails array in the gateway config and send it with a PATCH /admin/v1/gateways/{id} request:
curl -X PATCH https://<your-gateway-host>/admin/v1/gateways/{id} \
  -H "Content-Type: application/json" \
  -d '{
    "config": {
      "guardrails": [
        {
          "type": "language",
          "name": "latin-only",
          "action": "block",
          "target": "request",
          "allowed": ["latin"]
        }
      ]
    }
  }'

💡 Note: The guardrails array is replaced in full on each PATCH — include every detector the gateway should keep, not only the new one.

-> The language guardrail is saved and appears in the execution plan.


Pipeline position

The language guardrail is Tier 1 — it runs in-process with no external calls. It runs in both the request and response phases depending on the configured target. A block verdict stops the pipeline immediately.


See also