About Prompt
- Prompt Type – Dynamic
- Prompt Platform – ChatGPT, Grok, Deepseek, Gemini, Copilot, Midjourney, Meta AI and more
- Niche – Natural Language Processing
- Language – English
- Category – AI Models
- Prompt Title – Language Detection AI Prompt
Prompt Details
**Prompt Type:** Dynamic
**Platforms:** All AI Platforms
**Purpose:** Accurate and robust language detection across various text inputs.
**Prompt Structure:**
“`
Detect the language of the following text and provide the following information:
1. **Language Code (ISO 639-1):** The two-letter ISO 639-1 language code (e.g., “en” for English, “fr” for French, “es” for Spanish). If a specific dialect is identified (e.g., Canadian French), provide the broader language code (e.g., “fr”). If the language cannot be reliably identified, return “und” (undetermined).
2. **Language Name (English):** The full English name of the detected language (e.g., “English”, “French”, “Spanish”).
3. **Confidence Score:** A numerical score between 0 and 1 representing the model’s confidence in the language detection. A score closer to 1 indicates higher confidence.
4. **Script (Optional, if applicable):** If the language uses a specific script (e.g., Latin, Cyrillic, Arabic), indicate the script name. This is particularly useful for languages like Serbian which can be written in both Cyrillic and Latin scripts. If the script cannot be determined, omit this field.
5. **Dialect/Variant Information (Optional, if applicable):** If a specific dialect or regional variant can be confidently identified (e.g., American English, British English, Mexican Spanish), provide this information. If no specific dialect can be determined, omit this field.
**Input Text:**
{{input_text}}
**Output Format (JSON):**
“`json
{
“language_code”: “{{language_code}}”,
“language_name”: “{{language_name}}”,
“confidence_score”: {{confidence_score}},
“script”: “{{script}}”, // Optional
“dialect_variant”: “{{dialect_variant}}” // Optional
}
“`
**Example:**
**Input Text:**
Bonjour le monde! Comment allez-vous aujourd’hui ?
**Output (JSON):**
“`json
{
“language_code”: “fr”,
“language_name”: “French”,
“confidence_score”: 0.98,
“script”: “Latin”
}
“`
**Guidelines for Optimal Performance:**
* **Input Text Length:** While the prompt should handle texts of varying lengths, be aware of limitations on input size imposed by specific AI platforms. For very long texts, consider segmenting the text and processing each segment independently.
* **Mixed Language Inputs:** If the input text contains segments in multiple languages, specify whether the model should identify all languages present or focus on the dominant language. For identifying all languages, consider requesting the model to segment the text by language and provide language information for each segment.
* **Ambiguous Texts:** For short or ambiguous texts, the confidence score becomes especially crucial. If the confidence score is low, consider flagging the result as potentially unreliable.
* **Handling Code and Special Characters:** The prompt should be robust to inputs containing code snippets, URLs, special characters, and emojis. These elements should not interfere with accurate language detection.
* **Contextual Information:** When available, providing contextual information (e.g., source of the text, intended audience) can improve accuracy, especially for ambiguous cases. You can add an optional “context” field to the input.
**Error Handling:**
* **Invalid Input:** If the input text is empty, null, or contains only whitespace, return an appropriate error message in the JSON output. For example: `{“error”: “Invalid input: Empty or whitespace-only text.”}`
* **Unsupported Language:** If the model encounters a language it cannot identify (even as “undetermined”), return an appropriate error message indicating this limitation.
**Prompt Customization:**
This prompt can be further customized by adding specific instructions or constraints based on the particular use case. For example, you might specify a list of expected languages or prioritize certain languages over others. You can also specify the desired level of detail for dialect/variant information.
By following these guidelines and utilizing the provided prompt structure, you can leverage the power of AI models for accurate and efficient language detection across a wide range of applications.
“`