Skip to content
XUtilHub

AI-103 courseLesson 14 of 18 · 14 min

Text Analysis With LLMs and Azure Language: Entities, Sentiment, PII and Translation (AI-103)

XUtilHub Team ·

Exam skills covered

  • Implement solutions to extract entities, topics, summaries, and structured JSON outputs by using generative prompting and Foundry Tools
  • Configure detection of sentiment, tone, safety issues, and sensitive content
  • Build solutions that translate text by using Azure Translator in Foundry Tools or LLM‑powered translation flows
  • Customize language model outputs for domain tasks, such as compliance summarization and domain extraction

Text analysis on AI-103 is a choice between two toolkits: prompting a language model and Foundry Tools such as Azure Language and Azure Translator. This lesson shows both, and when to pick each.

Extract entities, topics and summaries as JSON with an LLM

LLMs extract almost anything you can describe, and structured outputs make the result machine-readable:

schema = {
    "type": "object",
    "properties": {
        "people": {"type": "array", "items": {"type": "string"}},
        "organisations": {"type": "array", "items": {"type": "string"}},
        "topics": {"type": "array", "items": {"type": "string"}},
        "summary": {"type": "string", "description": "Two sentences max"},
        "sentiment": {"type": "string", "enum": ["positive", "neutral", "negative", "mixed"]},
        "tone": {"type": "string", "enum": ["calm", "frustrated", "angry", "sarcastic", "urgent"]},
    },
    "required": ["people", "organisations", "topics", "summary", "sentiment", "tone"],
    "additionalProperties": False,
}

r = openai.responses.create(
    model="chat-main",
    instructions="Extract information from customer emails. Use only what the email says.",
    input=email_text,
    text={"format": {"type": "json_schema", "name": "email_analysis", "schema": schema, "strict": True}},
)

Validate the JSON in code anyway (types, enums, required fields), and log failures.

The same with Azure Language

Azure Language gives prebuilt, predictable APIs with confidence scores:

from azure.ai.textanalytics import TextAnalyticsClient

client = TextAnalyticsClient(endpoint=os.environ["LANGUAGE_ENDPOINT"], credential=DefaultAzureCredential())

docs = ["The checkout page at Contoso crashed twice. Call me on 555-0100, Maria Garcia."]
print(client.analyze_sentiment(docs)[0].sentiment)               # negative
print([e.text for e in client.recognize_entities(docs)[0].entities])
pii = client.recognize_pii_entities(docs)[0]
print(pii.redacted_text)                                          # names and phone number masked

Language capabilities include sentiment and opinion mining, named entities, PII detection and redaction, key phrases, language detection, summarisation, and custom models (custom classification, custom NER, conversational language understanding).

LLM or Azure Language?

NeedBetter fit
Fixed task, very high volume, low cost, predictable outputAzure Language
PII redaction for complianceAzure Language PII (deterministic, auditable)
Rich, changing labels (tone, intent, custom categories)LLM prompting
Summaries in a specific house formatLLM with instructions and examples
No training data for custom categoriesLLM (zero- or few-shot)

Detect sentiment, tone, safety issues and sensitive content

  • Sentiment: Azure Language returns positive, neutral, negative or mixed with scores per sentence; opinion mining links opinions to aspects ("battery: negative").
  • Tone: beyond sentiment (frustrated, sarcastic, urgent), use an LLM with defined labels.
  • Safety issues: Azure AI Content Safety text analysis classifies hate, sexual, violence and self-harm with severity, and supports custom blocklists.
  • Sensitive content: PII detection (names, addresses, card numbers, IDs), with categories you choose and a redaction policy

Combine them in a pipeline: detect language → redact PII → classify safety → analyse sentiment and tone → route.

Translate text

Azure Translator (a Foundry Tool) translates between 100+ languages:

import requests

resp = requests.post(
    f"{os.environ['TRANSLATOR_ENDPOINT']}/translate",
    params={"api-version": "3.0", "from": "en", "to": ["fr", "de", "ja"]},
    headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"},
    json=[{"text": "Your order has shipped."}],
)

Features to know: language detection, multiple target languages per call, transliteration, custom glossaries / dictionary for product names, Custom Translator models trained on your terminology, and document translation that keeps formatting for whole files. Microsoft also offers LLM-powered translation options.

LLM translation flows suit content where tone and context matter: marketing copy, localisation for a region's culture, or "translate and simplify for a 12-year-old". Add a glossary to the prompt and evaluate with bilingual reviewers.

Choose Translator when…Choose an LLM when…
High volume, many languages, cost per characterStyle, tone and cultural adaptation matter
Glossaries must be enforced exactlyYou want to translate and rewrite or summarise
Document formatting must be preservedContent is short and context-heavy

Customise outputs for domain tasks

For tasks such as compliance summarisation or domain extraction (clauses from contracts, findings from audit reports):

  1. Instructions with domain rules and definitions
  2. Few-shot examples of correct outputs
  3. An output template or JSON schema matching the team's format
  4. Grounding: only use the provided text, and quote the source sentence for each finding
  5. Evaluation against expert-labelled examples
  6. Fine-tuning only if prompting can't reach the required quality or cost

Checking summary length against a word limit? Use our word counter.

Key takeaways

  • LLM + structured outputs for flexible extraction (entities, topics, summaries, tone); Azure Language for predictable, prebuilt analysis and PII redaction.
  • Safety: Content Safety text categories and blocklists; sensitive data: PII detection.
  • Azure Translator for scale, glossaries and documents; LLM translation for tone and adaptation.
  • Domain tasks: instructions, examples, templates, grounding, evaluation, then fine-tuning if needed.

Next lesson: speech and voice agents.

Check your understanding

Exam-style questions on this lesson. Get them all right to mark the lesson complete.

Question 1

1.You must redact names, phone numbers and card numbers from chat logs with a predictable API. What do you use?

Question 2

2.Translating 50 languages with a custom glossary and predictable cost per character. Which is the better fit?

Question 3

3.What makes LLM extraction reliable enough to feed a database?

Question 4

4.How do you adapt summaries to a compliance team's required format?

Finished reading?

← AI-103 course outline