The Language Validator plugin enforces that incoming requests are written in a desired language. When a mismatch is detected, it gently steers the model by appending a short guidance note to the prompt, asking the model to respond in the specified language.

What it does

  • Detects the language of user-provided text before it reaches the model (pre-request stage)
  • If the detected language differs from your desired language, it appends a guidance hint to the prompt
  • Works transparently and is permissive if detection fails (i.e., it does not block the request)
Typical uses:
  • Enforce that all conversations happen in a single language (e.g., English)
  • Ensure compliance for markets or regions requiring a specific language
  • Improve user experience by keeping responses consistent with brand or locale

Configuration

Required and optional settings:
  • mapping_field (optional): JSON path to the request field containing the text to validate. If omitted, common fields such as prompt or input are used.
  • provider (required): Provider used for language detection. Currently supported: google.
  • api_key (conditional): Required when provider is google.
  • lang (required): The desired language code (e.g., en, es, fr).
Behavior notes:
  • Stage: PreRequest
  • If detection fails or no text is found, the plugin does nothing and allows the request to continue
  • If language differs, the plugin appends: [LanguageValidator] Please respond in <lang>.

Providers

  • Google: Uses Google Translate v2 Detect endpoint. Requires an API key.

Example configuration

Add the plugin to a rule’s actions list with the desired settings:
{
  "name": "language_validator",
  "priority": 1,
  "parallel": false,
  "settings": {
    "provider": "google",
    "api_key": "${GOOGLE_API_KEY}",
    "lang": "en",
    "mapping_field": "prompt"
  }
}
If mapping_field is omitted, the plugin will look for common top-level fields like prompt or input.

Best practices

  • Choose a single desired language per application or route to avoid confusion
  • Keep the guidance concise; the default prompt injection is short and effective
  • Combine with moderation or context security plugins for comprehensive safety
  • Monitor metrics to verify detection performance and adjust configuration