Skip to content
This repository was archived by the owner on Feb 13, 2026. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
# Overview

| Developed by | SCB 10X |
| --- | --- |
| Date of development | Feb 15, 2024 |
| Validator type | Quality |
| Blog | - |
| Blog | |
| License | Apache 2 |
| Input/Output | Output |

# Description
## Description

### Intended use
Validate that an LLM-generated text is in the expected language. If the text is not in the expected language, the validator will attempt to translate it to the expected language.

Use `fast-langdetect` library to detect the language of the input text,
and `iso-language-codes` library to get the language names from the ISO codes.

Utilize Meta's `facebook/nllb-200-distilled-600M` translation model (available on Huggingface) to translate the text from the detected language to the expected language.

## Intended use

- Primary intended uses: This validator is useful when you’re using multiple languages in an LLM application.
- Out-of-scope use cases: N/A

## Resources required
### Requirements

- Dependencies:
* Dependencies:
- guardrails-ai>=0.4.0
- fast_langdetect
- iso_language_codes
- transformers HuggingFace library
- facebook/nllb-200-distilled-600M translation model
- Foundation model access keys: HuggingFace

# Installation
* Foundation model access keys:
- HuggingFace

## Installation

```bash
$ guardrails hub install hub://scb-10x/correct_language

```
## Usage Examples

# Installation
### Validating string output via Python

## Validating string output via Python
In this example, we apply the validator to a string output generated by an LLM.

```python
Expand Down Expand Up @@ -70,7 +71,7 @@ Initializes a new instance of the ValidatorTemplate class.
</ul>
<br/>

**`validate(self, value, metadata) ValidationResult`**
**`validate(self, value, metadata) -> ValidationResult`**
<ul>
Validates the given `value` using the rules defined in this validator, relying on the `metadata` provided to customize the validation process. This method is automatically invoked by `guard.parse(...)`, ensuring the validation logic is applied to the input data.

Expand All @@ -80,7 +81,7 @@ Note:
2. When invoking `guard.parse(...)`, ensure to pass the appropriate `metadata` dictionary that includes keys and values required by this validator. If `guard` is associated with multiple validators, combine all necessary metadata into a single dictionary.

**Parameters**
- **`value`** *(Any):* The input value to validate.
- **`metadata`** *(dict):* A dictionary containing metadata required for validation. No additional metadata keys are needed for this validator.
- **`value`** *(Any)*: The input value to validate.
- **`metadata`** *(dict)*: A dictionary containing metadata required for validation. No additional metadata keys are needed for this validator.
</ul>