# LanguageDetector The `LanguageDetector` is an **input processor** that identifies the language of input text and optionally translates it to a target language for consistent processing. This processor helps maintain language consistency by detecting the language of incoming messages and providing flexible strategies for handling multilingual content, including automatic translation to ensure all content is processed in the target language. ## Usage example ```typescript import { LanguageDetector } from "@mastra/core/processors"; const processor = new LanguageDetector({ model: "openrouter/openai/gpt-oss-safeguard-20b", targetLanguages: ["English", "en"], threshold: 0.8, strategy: "translate" }); ``` ## Constructor parameters **options:** (`Options`): Configuration options for language detection and translation ### Options **model:** (`MastraModelConfig`): Model configuration for the detection/translation agent **targetLanguages?:** (`string[]`): Target language(s) for the project. If content is detected in a different language, it may be translated. Can be language name ('English') or ISO code ('en') **threshold?:** (`number`): Confidence threshold for language detection (0-1). Only process when detection confidence exceeds this threshold **strategy?:** (`'detect' | 'translate' | 'block' | 'warn'`): Strategy when non-target language is detected: 'detect' only detects language, 'translate' automatically translates to target language, 'block' rejects content not in target language, 'warn' logs warning but allows through **preserveOriginal?:** (`boolean`): Whether to preserve original content in message metadata. Useful for audit trails and debugging **instructions?:** (`string`): Custom detection instructions for the agent. If not provided, uses default instructions **minTextLength?:** (`number`): Minimum text length to perform detection. Short text is often unreliable for language detection **includeDetectionDetails?:** (`boolean`): Whether to include detailed detection info in logs **translationQuality?:** (`'speed' | 'quality' | 'balanced'`): Translation quality preference: 'speed' prioritizes fast translation, 'quality' prioritizes accuracy, 'balanced' balances between speed and quality **providerOptions?:** (`ProviderOptions`): Provider-specific options passed to the internal detection agent. Use this to control model behavior like reasoning effort for thinking models (e.g., \`{ openai: { reasoningEffort: 'low' } }\`) ## Returns **id:** (`string`): Processor identifier set to 'language-detector' **name?:** (`string`): Optional processor display name **processInput:** (`(args: { messages: MastraDBMessage[]; abort: (reason?: string) => never; tracingContext?: TracingContext }) => Promise`): Processes input messages to detect language and optionally translate content before sending to LLM ## Extended usage example ```typescript import { Agent } from "@mastra/core/agent"; import { LanguageDetector } from "@mastra/core/processors"; export const agent = new Agent({ id: "multilingual-agent", name: "multilingual-agent", instructions: "You are a helpful assistant", model: "openai/gpt-5.1", inputProcessors: [ new LanguageDetector({ model: "openrouter/openai/gpt-oss-safeguard-20b", targetLanguages: ["English", "en"], threshold: 0.8, strategy: "translate", preserveOriginal: true, instructions: "Detect language and translate non-English content to English while preserving original intent", minTextLength: 10, includeDetectionDetails: true, translationQuality: "quality" }) ] }); ``` ## Related - [Guardrails](https://mastra.ai/docs/agents/guardrails)