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
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
orinput
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
).
- 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