Analyzing Text with Azure Language and Azure Content Safety
This lesson explains the prebuilt, deterministic text analysis of Azure Language and Azure Content Safety, entities, sentiment, personal data and harmful content, and how to combine it with language models for tone and intent.
Learning outcomes
After completing this lesson, you will be able to:
- Identify the Azure Language features relevant to AI-103.
- Detect and redact PII in text.
- Combine sentiment and safety analysis with a language model.
Azure Language features
Azure Language is the Foundry Tool for prebuilt natural language processing. Each feature is a pretrained model for one task, so it returns the same kind of result for every input: a list of entities with categories, a sentiment label with scores, a language code. No prompt is written and no schema is designed; the request names the feature, and the response follows a documented format. Azure Language exposes its features through a single analyze-text endpoint on the Foundry resource (and through the Language SDK), with Microsoft Entra ID authentication.
The prebuilt features fall into three groups, and custom features cover tasks the prebuilt ones do not.
Extraction features find things in the text. Named entity recognition returns people, organizations, locations, dates and quantities with their offsets; personally identifiable information (PII) detection returns personal data and a redacted copy of the text; and key phrase extraction returns the main talking points.
Classification features label the text as a whole. Language detection identifies the language, and sentiment analysis labels each document and sentence as positive, negative, neutral or mixed, while opinion mining links each opinion to the aspect it concerns.
Summarization produces extractive summaries, which select existing sentences, or abstractive summaries, which write new text.
When the prebuilt categories do not fit, custom text classification and custom named entity recognition train models on labelled examples. This suits high-volume tasks where a trained model is cheaper and more consistent than prompting.
The following table summarizes the features.
| Feature | Returns | Typical use |
|---|---|---|
| Named entity recognition | Entities with categories (Person, Organization, Location, DateTime, Quantity and others), offsets, confidence | Indexing, routing, analytics |
| PII detection | PII entities with categories and a redacted text | Redact before storage or model calls |
| Key phrase extraction | Main phrases | Tagging and search |
| Language detection | Language and confidence | Routing to translation |
| Sentiment analysis and opinion mining | Labels and scores per document and sentence; aspects with opinions | Customer feedback analysis |
| Summarization | Extractive sentences or abstractive summary | Documents and conversations |
| Custom text classification, custom NER | Labels or entities from a trained model | High-volume domain-specific tasks |
Detecting sensitive content
Sensitive content in text usually means personally identifiable information (PII): any data that identifies a person directly or in combination with other data. Text from customers, such as emails, reviews and chat transcripts, often contains PII, and privacy rules may forbid storing it, logging it or sending it to other services. Detecting it is the first step in removing it.
PII detection finds categories such as names, phone numbers, email addresses, government identification numbers and financial account numbers, returns their offsets and produces a redacted copy of the text. Requests can limit the categories, choose a redaction policy (for example masking with a character or replacing with the entity type) and process conversations. Redacting before storing text, writing logs or sending content to a third-party tool reduces exposure. Guardrails can also detect PII in model inputs and outputs.
import requests
body = {"kind": "PiiEntityRecognition",
"parameters": {"modelVersion": "latest", "piiCategories": ["Person", "PhoneNumber", "Email"]},
"analysisInput": {"documents": [{"id": "1", "language": "en", "text": text}]}}
r = requests.post(f"{ai_endpoint}/language/:analyze-text?api-version=2024-11-01",
json=body, headers=bearer()).json()
print(r["results"]["documents"][0]["redactedText"])The following screenshot shows the Text PII Redaction playground in the Foundry portal on a fictional review. Each detected entity is returned with its category, confidence, offset and length, and the redacted text replaces it with asterisks.

Redact personal data
Sentiment, tone and safety
Beyond what a text says, applications often need to know how it is said: whether the writer is satisfied, whether they are angry or urgent, and whether the text is harmful. These are three different questions, and each is answered by a different tool.
Sentiment analysis gives positive, neutral, negative or mixed labels with confidence scores. Opinion mining extends it by linking opinions to aspects, such as negative about delivery and positive about quality.
Tone and intent, such as urgency, sarcasm, frustration or threat of cancellation, are not prebuilt categories. An LLM with a fixed label set detects them.
Safety issues are detected with Azure Content Safety text analysis (hate, sexual, violence and self-harm severities), Prompt Shields for attacks and custom blocklists for prohibited terms.
Analyze the text
A feedback pipeline
A retailer collects 50,000 product reviews a week. It needs per-aspect sentiment for analytics, removal of customers' phone numbers and emails before reviews are stored, and rejection of abusive reviews before publication.
Use Azure Language PII detection with the PhoneNumber and Email categories to redact, opinion mining for aspect-level sentiment, and Azure Content Safety text analysis with a severity threshold for abuse. An LLM prompt could approximate each step but without offsets, deterministic redaction or calibrated severities.
Which feature gives sentiment for individual aspects, such as food and service, in one review?
Show answer
Opinion mining in Azure Language.
Exam Tips
Remember for the exam
- Deterministic PII redaction with categories and offsets: Azure Language PII detection.
- Aspect-level sentiment: opinion mining.
- Custom tone or intent labels: an LLM with an enum; harmful content: Azure Content Safety.