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)
- 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 Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
mapping_field | string | JSON path to the field containing text. Falls back to common fields like prompt or input | No | — |
provider | string | Language detection provider. Supported: google | Yes | — |
api_key | string | API key for the provider. Required when provider is google | Cond. | — |
lang | string | Desired language code (e.g., en, es, fr) | Yes | — |
- 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: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