Language
Enforce language-specific guardrails. Restrict outputs to desired languages and filter unsafe terms.
A class for scanning the prompt for different languages detection.
The Guardrail supports the 22 languages:
arabic (ar), bulgarian (bg), german (de), modern greek (el), english (en), spanish (es), french (fr), hindi (hi), italian (it), japanese (ja), dutch (nl), polish (pl), portuguese (pt), russian (ru), swahili (sw), thai (th), turkish (tr), urdu (ur), vietnamese (vi), and chinese (zh)Parameters:
data:
prompt(str): The prompt to check for language.valid_languages(Sequence[str]): A list of valid language codes in ISO 639-1.
arguments:
threshold(float, optional): Minimum confidence score. Default is 0.6.match_type(str, optional): Whether to match the full text or individual sentences. Default isfull. Options aresentenceorfulluse_onnx(bool, optional): Whether to use ONNX for inference. Default is False.
Interpretation:
Passed if valid languages are found in the text, Fails if invalid language is detected above the threshold.
Example:
Passed Scenario -
evaluator.add_test(
test_names=["language_guardrail"],
data={
"prompt": """Craft a poem that captures the breathtaking beauty and serenity of this underwater world.
Describe the gentle swaying of the coral, the playful dance of the fish, and the mesmerising underwater soundscape.
Use vivid imagery and metaphors to evoke a sense of awe and wonder for this natural treasure.""",
},
arguments={"threshold": 0.6, "valid_languages":["en"]},
).run()
Result = "Only valid languages are found in the text".Failed Scenario -
Code Example:
Last updated
Was this helpful?

