
Language detection
When your application receives user text but the language is unknown, the Azure AI Language SDK can determine the most likely language automatically. Use thedetect_language method and supply the text. The service analyzes the input and returns structured details you can act on.
The response includes:
- Human-readable language name (e.g., French).
- ISO 639-1 language code (e.g.,
fr,en,es). - Confidence score (closer to 1.0 indicates higher confidence).
- SDK call:
client.detect_language([text]) - Input:
"bonjour" - Typical output:
name: French,iso6391_name: fr,confidence_score: 0.99
- Automatically identify the language of incoming messages (support tickets, chat logs).
- Route content to translation or language-specific business logic.
- Validate user-submitted content against expected language constraints.

PII detection (recognize_pii_entities)
PII (personally identifiable information) includes names, phone numbers, email addresses, postal addresses, and other values that can identify or contact a person. The SDK exposesrecognize_pii_entities to detect such entities and optionally return a redacted version of the text.
Example input:
- “Sara can be reached at 888-901-2828.”
- Identified entities and categories (e.g.,
Person,PhoneNumber) with confidence scores. - A
redacted_textfield where sensitive values are masked or replaced to avoid exposure.
- Masking sensitive information before storing logs or sharing text.
- Meeting privacy and compliance requirements by automatically redacting PII.
- Building automated data governance and redaction pipelines at scale.
Quick comparison: specialized SDK methods vs general-purpose models
For scenarios requiring consistent, structured outputs (like language code and confidence or masked text), prefer the SDK methods or specialized models. General-purpose models can be more variable and often need additional parsing or prompt constraints to produce reliable, machine-friendly results.

SDK example (Python)
A concise Python example showing authentication, language detection, and PII recognition using the Azure Text Analytics client. Replace the placeholder values with your actual key and endpoint, or set them via environment variables.Notes about usage and best practices
- The SDK returns structured, easy-to-consume results (for example,
primary_language.name,primary_language.iso6391_name, andprimary_language.confidence_score). - For PII detection,
doc.redacted_textprovides masked text anddoc.entitieslists identified PII entities with categories and confidence scores. - Use specialized SDK endpoints or language models when you need deterministic JSON outputs for downstream processing or compliance.
- When using general-purpose generative models for structured tasks, add robust instructions and parsing logic to normalize outputs.