TextLanguageRouter
Use TextLanguageRouter to route text strings to different pipeline branches based on their detected language. Text that doesn't match any of the specified languages is sent to an unmatched output.
Key Features
- Detects the language of a text string and routes it to the matching output
- Supports any language available in the
langdetectlibrary using ISO language codes - Creates one named output per language for direct downstream connections
- Routes non-matching text to a dedicated
unmatchedoutput - Defaults to English detection if no languages are specified
Configuration
- Drag the
TextLanguageRoutercomponent onto the canvas from the Component Library. - Click the component to open the configuration panel.
- Configure the parameters as needed.
Connections
TextLanguageRouter accepts a single text string as input. It creates one output per language code in languages and an unmatched output for text whose detected language isn't in the list. Connect each output to the appropriate downstream component (for example, separate prompt builders or generators for different languages).
To route documents by language instead of raw text, use DocumentLanguageClassifier followed by MetadataRouter.
Usage Example
components:
TextLanguageRouter:
type: components.routers.text_language_router.TextLanguageRouter
init_parameters:
Parameters
Inputs
| Parameter | Type | Default | Description |
|---|---|---|---|
text | str | A text string to route. |
Outputs
The component creates one output per language code in languages, plus an unmatched output for text in languages not in the list.
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
languages | Optional[List[str]] | None | A list of ISO language codes. See the supported languages in the langdetect documentation. If not specified, defaults to ["en"]. |
Run Method Parameters
These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.
| Parameter | Type | Default | Description |
|---|---|---|---|
text | str | A text string to route. |
Was this page helpful?