Skip to main content

Language Validator

The language-validator policy checks input text against language allow or deny lists. Use apply_to: input. The gateway does not enforce output language.

Supported detected languages

At this time, the detector recognizes these ISO-like codes:

  • en
  • es
  • fr
  • de
  • zh
  • ja
  • ko
  • ar
  • pt
  • ru

Configuration

pack:
name: language-validator
version: "1.0.0"
enabled: true

policies:
chain:
- language-validator

policy:
language-validator:
allowed_languages:
- en
- fr
denied_languages: []
min_confidence: 0.5
action: block
apply_to: input

Fields

FieldTypeDescriptionDefault
allowed_languagesstring[]Allowed language codes. A non-empty list rejects a detected code that is not in the list.[]
denied_languagesstring[]Denylist of detected language codes. Used only when allowed_languages is empty.[]
min_confidencenumberMinimum confidence for an action. The gateway allows a result below this value.0.5
action"block" | "warn"block returns a block verdict. warn allows the request and records a warning-style cause code."block"
apply_to"input" | "output" | "both"Set input explicitly. both checks input only. output does not enforce language.runtime default: "input"

How it works

  1. Text selection: The gateway makes one string from user and system input messages.
  2. Detection: Local Unicode-block and trigram rules detect the language.
  3. Confidence check: The gateway allows detections below min_confidence.
  4. Policy check: The gateway compares the language with allowed_languages or denied_languages.
  5. Verdict: block returns a block verdict. warn returns allow with a warning cause.

Correct examples

English-only input gate

pack:
name: english-only
version: "1.0.0"
enabled: true

policies:
chain:
- language-validator

policy:
language-validator:
allowed_languages:
- en
min_confidence: 0.6
action: block
apply_to: input

Use warn on denied languages without blocking

pack:
name: routing-observability
version: "1.0.0"
enabled: true

policies:
chain:
- language-validator

policy:
language-validator:
denied_languages:
- ja
- ar
min_confidence: 0.4
action: warn
apply_to: input

Important limitations

  • Output language enforcement is not supported. Use apply_to: input. output skips checks, and both checks input only.
  • Streaming startup rejects apply_to: output and apply_to: both with streaming.policy_cannot_enforce.
  • The active lint schema shows a different default. Always set apply_to: input.
  • The detector only recognizes the supported language set listed above.
  • Mixed-language or short text can have a result below min_confidence. The gateway allows this text.

Best practices

  • Prefer allowed_languages for strict input control.
  • Start with action: warn if traffic measurement is necessary before block enforcement.
  • Add prompt-injection or pii-detector when their different input controls are necessary.

Next steps