Skip to main content
Explore common methods in the Azure AI Language SDK for detecting text language and identifying personally identifiable information (PII). These SDK calls help you reliably route multilingual content and protect sensitive data with deterministic, structured results.
A presentation slide titled "Azure AI Language SDK: Common Methods." It features a teal curved background on the right and an icon of chat/message bubbles.

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 the detect_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).
Example usage:
  • SDK call: client.detect_language([text])
  • Input: "bonjour"
  • Typical output: name: French, iso6391_name: fr, confidence_score: 0.99
Common scenarios for language detection:
  • 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.
A diagram illustrating language detection: the input "Bonjour" goes through detect_language() and outputs language details. The result box shows "French" (code: fr) with a confidence of 0.99.

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 exposes recognize_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.”
What the service provides:
  • Identified entities and categories (e.g., Person, PhoneNumber) with confidence scores.
  • A redacted_text field where sensitive values are masked or replaced to avoid exposure.
Common PII use cases:
  • 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.
A screenshot of the Microsoft Foundry/Azure AI playground showing the gpt-4.1-mini deployment UI with instructions and tools on the left. The chat pane on the right shows the message "Bonjour" and a detected language label "French."

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, and primary_language.confidence_score).
  • For PII detection, doc.redacted_text provides masked text and doc.entities lists 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.
With these examples and best practices, you can integrate language detection and PII recognition into your applications to automate multilingual workflows and protect sensitive information.

Watch Video