Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 21 of 30
❮Prev Next❯

Build a Text Analysis App

Module 2: Microsoft Foundry ⏱ 9 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    30-second answer

    A lightweight text analysis app sends text to Azure Language in Foundry Tools through the azure-ai-textanalytics Python package. With a TextAnalyticsClient (endpoint + key) you call analyze_sentiment, extract_key_phrases, recognize_entities, recognize_pii_entities for redaction, and begin_abstract_summary for summaries. You can also get the same insights by prompting a deployed language model, which is more flexible but less predictable.

    Simulate it » No Azure account needed

    Exam objective: 2.2.1 Build a lightweight application that includes text analysis. (Skills measured as of April 15, 2026)

    Simulations

    Feel it before you read it. No account needed, nothing leaves this page.

    Azure portal: Analyse text with Azure Language Test the features first, then grab the code.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading the portal…

    Open <strong>Foundry Tools ➜ Azure Language</strong>, pick <strong>Analyze sentiment</strong> and paste a review.

    👆 Click the glowing item in the portal to continue

    Read the steps as text
    1. Open Foundry Tools ➜ Azure Language, pick Analyze sentiment and paste a review.
    2. Sentiment comes per document and per sentence, and opinion mining links each opinion to its target (breakfast ➜ cold).
    3. Switch capability: key phrases, named entities, PII redaction, language detection and summarization.
    4. The same calls in Python use the resource endpoint with TextAnalyticsClient.

    🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.

    😟 THE PROBLEM

    Product reviews need a mood score before they reach the dashboard.

    😊 THE SOLUTION

    A small app that calls Azure Language for each review.

    • No mood score✓ analyze_sentiment
    • No topics✓ extract_key_phrases
    • Private data leaks✓ recognize_pii_entities
    🛠️ Solved with: Text analysis app

    Start with a question

    What if a thousand reviews landed overnight and your boss wants a summary by 10 a.m.?

    A food-delivery app gets reviews like “Biryani was great but the rider called me five times, my number is 98xxxxxx12”. Someone has to work out the mood, spot what people talk about, and keep phone numbers out of the report.

    Reading them all isn’t going to happen. A small Python app that sends each review to Azure Language can do it before your tea’s ready.

    Explain it like I’m 10

    The technical explanation

    Azure Language in Foundry Tools gives you ready-made text analysis behind one endpoint. If you have a Foundry resource you already have it. Copy the endpoint and a key from the resource (or use Microsoft Entra ID), and install the SDK.

    pip install azure-ai-textanalytics
    export LANGUAGE_ENDPOINT="https://<resource-name>.cognitiveservices.azure.com/"
    export LANGUAGE_KEY="<key>"
    FeatureMethodWhat you get back
    Sentiment analysisanalyze_sentimentpositive / neutral / negative / mixed, scores per sentence
    Key phrase extractionextract_key_phrasesA list of main talking points
    Named entity recognitionrecognize_entitiesText, category (Person, Location, DateTime…), confidence
    PII detectionrecognize_pii_entitiesPersonal data found, plus redacted_text
    Language detectiondetect_languageLanguage name and ISO code
    Summarizationbegin_abstract_summary / begin_extract_summaryNew summary sentences, or the key existing sentences

    text_app.py

    import os
    from azure.core.credentials import AzureKeyCredential
    from azure.ai.textanalytics import TextAnalyticsClient
    
    client = TextAnalyticsClient(
        endpoint=os.environ["LANGUAGE_ENDPOINT"],
        credential=AzureKeyCredential(os.environ["LANGUAGE_KEY"]),
    )
    
    reviews = [
        "The biryani was excellent but the rider called me five times. "
        "Call me on 9876543210 if there's a refund. Ordered in Chennai on Friday."
    ]
    
    # Every method takes a LIST of documents and returns one result per document
    sentiment = client.analyze_sentiment(reviews)[0]
    print("Sentiment:", sentiment.sentiment, sentiment.confidence_scores)
    
    phrases = client.extract_key_phrases(reviews)[0]
    print("Key phrases:", phrases.key_phrases)
    
    for entity in client.recognize_entities(reviews)[0].entities:
        print(f"Entity: {entity.text} ({entity.category}, {entity.confidence_score:.2f})")
    
    pii = client.recognize_pii_entities(reviews)[0]
    print("Redacted:", pii.redacted_text)  # the phone number comes back as asterisks
    
    # Summaries run as a long-running operation
    poller = client.begin_abstract_summary(reviews)
    for doc in poller.result():
        print("Summary:", doc.summaries[0].text)

    For that review you’d expect mixed sentiment (great food, annoying rider), key phrases like “biryani” and “rider”, entities such as Chennai (Location) and Friday (DateTime), and a redacted line with the number masked.

    The alternative: ask a deployed model

    You can get the same insights by prompting a chat model in Foundry, using the Foundry SDK from the chat app lesson:

    response = openai.responses.create(
        model="gpt-4.1-mini",  # deployment name
        instructions="Return JSON with sentiment, key_phrases and entities. Replace phone numbers with ***.",
        input=reviews[0],
    )
    print(response.output_text)

    Azure Language

    • Fixed, well-defined outputs
    • Confidence scores built in
    • Same input gives the same output
    • Simple per-text pricing, built for volume

    Prompting an LLM

    • Any analysis you can describe
    • Output shape depends on your prompt
    • Can vary between runs
    • Pay per token, check results with evaluations
    Azure Language vs prompting a generative model
    Architect level Plan for the 2029 retirements

    Microsoft has announced that key phrase extraction, sentiment analysis, summarization, entity linking, conversational language understanding and custom question answering in Azure Language retire on 31 March 2029, with Foundry models as the suggested path. Language detection, PII detection, NER and Text Analytics for health continue. A new project that leans on sentiment or summaries should either plan a move to prompts on a deployed model or start there.

    Real-world business scenario

    Consumer apps

    A Bengaluru food-delivery start-up

    The problem
    Thousands of app reviews and chat transcripts a day, with customers often pasting phone numbers and addresses into them. The support lead needed daily themes without staff reading personal data.
    What they used
    A nightly Python job using azure-ai-textanalytics: recognize_pii_entities first, then sentiment and key phrases on the redacted text, with results written to a dashboard.
    Why that choice
    Fixed outputs with confidence scores were easy to chart day over day, and redaction kept personal data out of the reporting store.
    The result
    The team spotted a spike of 'late rider' complaints in one city within a day instead of a week.

    When to use it and when not to

    ✓ Use it when…

    • You need the same structured result for thousands of texts, like sentiment per review.
    • Personal data must be masked before text is stored or shared.
    • You want confidence scores so low-certainty results can go to a person.

    ✕ Think twice when…

    • The question is open-ended, like "what do customers wish we sold?". Prompt a generative model instead.
    • You are starting a new long-term project on a feature that retires in 2029 without a plan to move.

    ↔ Alternatives to consider

    • Prompting a deployed model such as gpt-4.1-mini for custom analysis.
    • Content Understanding when the text lives inside documents, audio or video.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    Test yourself with exercises

    5 original practice questions in the AI-901 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.

    Question 1

    Question 1 of 5

    A support application stores customer chat transcripts. Before storage, phone numbers and email addresses must be masked. You use the azure-ai-textanalytics package.

    Which method should you call?

    Question 2

    Question 2 of 5

    A product review contains both strongly positive and strongly negative sentences. Which overall sentiment label is Azure Language most likely to return?

    Question 3

    Question 3 of 5 · Select 2

    You create a TextAnalyticsClient in a Python application. Which TWO values must you provide?

    Question 4

    Question 4 of 5

    You need to identify people, locations and dates mentioned in news articles. Which method should you use?

    Question 5

    Question 5 of 5

    A team needs an analysis that Azure Language does not provide as a fixed feature, such as listing only the complaints about delivery in each review. What should the team use?

    Interview preparation

    Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.

    Beginner Which Azure service would you use to find the sentiment of customer reviews?

    Model answer

    Azure Language in Foundry Tools. I'd call analyze_sentiment from the azure-ai-textanalytics package and get back positive, neutral, negative or mixed, with confidence scores for each sentence.

    Interviewer follows up

    What does the app need to connect?

    You

    The resource endpoint and a key (or a Microsoft Entra ID credential). I keep both in environment variables, never in the code.

    Intermediate How would you remove phone numbers and emails from support tickets before storing them?

    Model answer

    Call recognize_pii_entities. Each result has the entities it found and a redacted_text property with the personal data masked by asterisks, so I'd store redacted_text instead of the original.

    Experienced developer Would you use Azure Language or an LLM prompt for sentiment analysis?

    Model answer

    Azure Language when I want the same structured output every time, with labels and confidence scores, at high volume. An LLM prompt when I need something the fixed features don't do, like 'list the complaints about delivery only'. Microsoft has also announced that some Language features, including sentiment and key phrases, retire in March 2029 in favour of Foundry models, so new projects should weigh that.

    Scenario Your app returns 'neutral' for a review written in Tamil. What do you check?

    Model answer

    I'd check that I'm passing the right language code, or run detect_language first, and confirm that the feature supports that language. Sending text with the wrong language hint is a common reason for odd results.

    Quick revision

    Key points

    • pip install azure-ai-textanalytics; create TextAnalyticsClient(endpoint, AzureKeyCredential(key)).
    • analyze_sentiment returns a label plus confidence scores per document and sentence.
    • extract_key_phrases, recognize_entities and recognize_pii_entities each take a list of documents.
    • recognize_pii_entities gives redacted_text with personal data masked.
    • Summaries are long-running operations, begin_abstract_summary or begin_extract_summary.

    Important terminology

    Azure Language in Foundry Tools
    The Foundry Tools service (formerly Azure AI Language) for sentiment, key phrases, entities, PII, summarization and more.
    TextAnalyticsClient
    The Python client from azure-ai-textanalytics that calls Azure Language text analysis features.
    PII redaction
    Finding personal data such as phone numbers and email addresses and masking it, returned as redacted_text.
    Confidence score
    A number from 0 to 1 that says how sure the service is about a sentiment label or an entity.
    Abstractive summary
    A summary written in new sentences, as opposed to an extractive summary that picks existing sentences.

    Common mistakes

    • Passing a single string instead of a list of documents to the client methods.
    • Confusing entity recognition (people, places, dates) with key phrases (main talking points).

    Exam tips

    • "Mask phone numbers in transcripts" = PII detection (redacted_text).
    • "Main talking points of a review" = key phrase extraction.
    • "Positive or negative" = sentiment analysis.

    Five quick revision questions

    1. 1.Which Python package calls Azure Language text analysis?Show

      azure-ai-textanalytics

    2. 2.Which method masks personal data?Show

      recognize_pii_entities (use redacted_text).

    3. 3.What range do confidence scores use?Show

      0 to 1.

    4. 4.Which sentiment label means both positive and negative sentences?Show

      Mixed.

    5. 5.How else can you get these insights besides Azure Language?Show

      Prompt a deployed generative model in Foundry.

    Official references

    Finished this lesson? Tick it off. Your progress is saved in this browser.

    Next up: Answer Spoken Prompts with a Multimodal Model

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.