Your profile

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

Lesson 30 of 39
❮Prev Next❯

Extract Entities, Summaries and Structured JSON

Module 4: Text & Speech ⏱ 11 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

    Use Azure Language in Foundry Tools when you want fixed, predictable output: named entity recognition (people, places, dates, with confidence scores), PII redaction and summaries. Use a model deployment when you need your own fields. Ask for JSON mode and you only get valid JSON. Ask with structured outputs (a JSON schema with strict: true, every field required) and the reply follows your shape every time. For domain summaries such as compliance, don't train anything first: give the model a role, a checklist, a glossary and one example at temperature 0. For your own entity types at high volume, train custom NER.

    Simulate it » No Azure account needed

    Exam objective: 4.1.1 Extract entities, topics, summaries and structured JSON outputs by using generative prompting and Foundry Tools. 4.1.4 Customize language model outputs for domain tasks, such as compliance summarization and domain extraction. (Skills measured as of April 16, 2026)

    Simulations

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

    Azure portal: Extract entities with Azure Language, then strict JSON from a model Extract entities with Azure Language, then ask a model for strict JSON.
    </> Embed

    Embed this simulation

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

    Loading the portal…

    In your Foundry project open <strong>Discover → Foundry Tools</strong> and pick <strong>Azure Language</strong>. It runs on the same Foundry resource as your models.

    👆 Click the glowing item in the portal to continue

    Read the steps as text
    1. In your Foundry project open Discover → Foundry Tools and pick Azure Language. It runs on the same Foundry resource as your models.
    2. Pick Extract named entities and paste a support ticket. These capabilities are fixed: same input, same output shape, every time.
    3. Each entity has a category and a confidence score. Look at the order number: that's the limit of prebuilt NER.
    4. Now try a model. In Build → Playgrounds, pick your gpt-4.1-mini deployment and tell it to extract fields. Temperature 0 keeps extraction steady.
    5. Write the shape you need as a JSON schema: every property listed in required, and additionalProperties: false. Strict mode needs both.
    6. In code, structured outputs go in text.format (Responses API) or response_format (Chat Completions). The reply now matches your schema every time.
    7. For domain tasks like compliance summaries, the instructions carry the domain: the role, a checklist, a glossary and a couple of worked examples. Fine-tune only if that still can't hold the format.

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

    😟 THE PROBLEM

    Support tickets are free text, and the ticketing system needs clean fields it can trust.

    😊 THE SOLUTION

    Use Azure Language for fixed entity categories, and a model with a strict JSON schema for your own fields.

    • People, places and dates buried in text✓ Azure Language named entity recognition
    • The model invents its own JSON keys✓ A JSON schema with strict: true
    • Summaries that miss amounts and control IDs✓ A domain prompt with a checklist and an example
    🛠️ Solved with: Azure Language and structured outputs

    Start with a question

    What if the ticket says 'order 48213' and your system wants an order_id field?

    Priya from Fabrikam Retail writes in: “Order 48213 arrived on 12 November with a cracked screen.” A person sees the name, the company, the date and the order straight away. Your ticketing system doesn’t read sentences. It wants fields, and it throws an error if one is missing.

    You have two tools. Azure Language is a trained reader with fixed categories. A model is a flexible reader that can return any shape you describe. The skill is knowing which one to use, and how to make the model’s answer something code can trust.

    Explain it like I’m 10

    The technical explanation

    Azure Language: entities, PII and summaries

    Azure Language in Foundry Tools (the service formerly called Azure AI Language) runs on your Foundry resource. The calls are the same across features: send documents, get a result per document.

    FeatureReturnsGood for
    Named entity recognitionEntities with a category (Person, Organization, Location, DateTime, Quantity and more) and a confidence scoreStandard facts in tickets, emails, contracts
    PII detectionEntities plus redacted textMasking personal data before storage or before an agent reads it
    Abstractive summarizationA short summary written in new sentencesLong documents and conversations
    Custom NERYour own entity typesRepeated extraction of business fields

    Prebuilt categories are fixed. An order number often comes back as a Quantity, because the service doesn’t know your business.

    from azure.identity import DefaultAzureCredential
    from azure.ai.textanalytics import TextAnalyticsClient
    
    client = TextAnalyticsClient(endpoint=ENDPOINT, credential=DefaultAzureCredential())
    result = client.recognize_entities([ticket_text])[0]
    for e in result.entities:
        print(e.text, e.category, round(e.confidence_score, 2))
    
    pii = client.recognize_pii_entities([ticket_text], categories_filter=["PhoneNumber", "Email"])[0]
    print(pii.redacted_text)

    Strict JSON from a model

    A model can return your own fields. Three levels of control:

    1. Plain text prompt: “Return JSON.” It usually works until it doesn’t. Don’t parse this in production.
    2. JSON mode (response_format={"type": "json_object"}): the reply is valid JSON. The keys are still the model’s idea.
    3. Structured outputs (response_format of type json_schema with strict: true): the reply matches your schema.
    schema = {
      "name": "ticket",
      "strict": True,
      "schema": {
        "type": "object",
        "properties": {
          "customer": {"type": "string"},
          "order_id": {"type": "string"},
          "priority": {"type": "string", "enum": ["low", "normal", "high"]},
          "churn_risk": {"type": "boolean"}
        },
        "required": ["customer", "order_id", "priority", "churn_risk"],
        "additionalProperties": False
      }
    }
    resp = openai_client.chat.completions.create(
        model="gpt-4.1-mini",
        messages=[{"role": "user", "content": ticket_text}],
        response_format={"type": "json_schema", "json_schema": schema},
    )

    For strict mode, list every property in required and set additionalProperties to false. An enum keeps a field to values your code understands.

    Domain tasks: compliance summaries and domain extraction

    A plain request such as “summarise this policy update” gives a nice paragraph that an auditor can’t use. Fix the prompt before you think about training.

    • Role: “You are a compliance analyst writing for the audit team.”
    • Checklist: WHAT changed, WHO is responsible, DEADLINE, CONTROL ID, RISK.
    • Glossary: what “PCI-07” or “four-eyes check” mean in your company.
    • Example: one policy update and the summary you’d accept, including “Not stated” for something missing.
    • Temperature 0, so the layout doesn’t wander.

    If prompting still can’t hold the format, consider fine-tuning. If the job is pulling the same fields from huge volumes, custom NER in Azure Language is usually cheaper and steadier than prompting a large model every time.

    Architect level Check what's changing in Azure Language

    Microsoft has announced retirement dates for some Azure Language features, with Foundry models as the suggested path. As announced on Microsoft Learn (checked 25 November 2026), entity recognition, PII detection and language detection continue, while features such as sentiment analysis, key phrase extraction and summarization are listed for retirement on 31 March 2029. For a new, long-lived project, read the current retirement notice before you build on a feature, and plan a prompt-based version of anything on that list.

    Real-world business scenario

    Retail

    Fabrikam Retail (fictional)

    The problem
    Support agents retyped customer name, order ID and priority from emails into the ticketing system, and the quarterly compliance summaries left out deadlines and control IDs.
    What they used
    Azure Language PII detection to mask card and phone numbers, a gpt-4.1-mini deployment with a strict JSON schema for the ticket fields, and a domain prompt with a checklist and an example for compliance summaries.
    Why that choice
    Redaction came from a fixed, predictable service. The schema meant the ticketing API never received a missing field, and the checklist made every summary list the same five items.
    The result
    Ticket entry time dropped from about four minutes to seconds, and the audit team stopped sending summaries back for missing deadlines.

    When to use it and when not to

    ✓ Use it when…

    • The categories are standard and you want the same output every time (Azure Language).
    • Code downstream needs exact fields (a model with structured outputs).
    • Summaries must include a fixed list of items (a domain prompt with an example).

    ✕ Think twice when…

    • You rely on JSON mode and assume every field will be there.
    • You fine-tune before trying a better prompt and a few examples.
    • You expect prebuilt entities to know your order IDs or policy numbers.

    ↔ Alternatives to consider

    • Custom NER for your own entity types at high volume.
    • Content Understanding when the source is a scanned form or invoice rather than text.
    • A reasoning model for judgments that need several steps.
    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-103 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 receives free-text tickets. The ticketing system requires a fixed set of fields, and a missing field must never reach it. You use a model deployment. What should you configure?

    Question 2

    Question 2 of 5

    An application must find people, organizations, locations and dates in thousands of emails each hour. The categories are the standard ones, and results must be identical for identical input. Which approach meets the requirements with the least effort?

    Question 3

    Question 3 of 5

    A bank needs summaries of policy updates for an audit team. Each summary must list the change, the role responsible, the deadline and the control ID, and must say "Not stated" when information is missing. Plain summaries omit these items. What should you do first?

    Question 4

    Question 4 of 5

    A company extracts the same three fields, policy ID, control ID and approval role, from 100,000 documents each month. Prebuilt entity categories do not cover these fields. The output must be predictable and cost-effective at this volume. Which option fits best?

    Question 5

    Question 5 of 5 · Select 2

    You use Azure Language to process support tickets. Which two outputs does it provide without any model training? Each correct answer presents a complete solution.

    Interview preparation

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

    Beginner What's the difference between JSON mode and structured outputs?

    Model answer

    JSON mode makes sure the reply parses as JSON, nothing more. The keys can be anything, and some can be missing. Structured outputs take a JSON schema and make the reply match it. With strict true, every field is required and extra fields aren't allowed, so my code can rely on the shape.

    Intermediate When would you pick Azure Language over a model for extraction?

    Model answer

    When the categories are standard and I want the same output for the same input, at volume and a low price. Named entities, PII and summaries come back with a fixed shape and confidence scores. I'd pick a model when I need my own fields or a free-form judgment.

    Experienced developer A compliance summary keeps leaving out the deadline and control ID. How do you fix it?

    Model answer

    I'd write a developer message with the reader's role, a checklist of required items, a short glossary, and one worked example that shows "Not stated" for missing items. Then temperature 0 and an evaluation on a few dozen real documents. Only if that can't hold the format would I look at fine-tuning.

    Scenario Three teams want the same four fields from 100,000 contracts a month. What do you build?

    Model answer

    I'd label a few hundred contracts and train a custom NER model in Azure Language, because the fields repeat and the volume is high. It's cheaper and steadier than prompting a large model every time. For the odd contract with unusual wording I'd keep a model with a strict schema as a fallback.

    Quick revision

    Key points

    • Azure Language gives fixed categories, confidence scores and the same output for the same input.
    • Prebuilt NER can't know your own fields. Use custom NER or a model for those.
    • JSON mode means valid JSON only. Structured outputs with strict true means your schema.
    • Strict schemas need every property listed in required and additionalProperties set to false.
    • Domain summaries come from role, checklist, glossary, example and temperature 0.

    Important terminology

    Named entity recognition (NER)
    An Azure Language feature that finds people, organizations, locations, dates and other categories in text and returns a category and a confidence score for each.
    PII detection
    An Azure Language feature that finds personal data and returns a redacted copy of the text. It can be limited to the categories you list.
    JSON mode
    A model setting that makes the reply valid JSON. It doesn't guarantee which keys are present.
    Structured outputs
    A model setting that makes the reply match a JSON schema you supply. With strict set to true, every field is required and no extra fields are allowed.
    Domain prompt
    Instructions that give a model a role, a checklist, a glossary and an example so its output suits one field, such as compliance.
    Custom NER
    A model you train in Azure Language on labelled examples so it extracts your own entity types, such as PolicyId or ApprovalRole.

    Common mistakes

    • Thinking JSON mode guarantees the fields you asked for.
    • Fine-tuning before trying a better prompt.
    • Expecting prebuilt NER to return order numbers or policy IDs as their own category.

    Exam tips

    • "Reply must match a schema" = structured outputs, not JSON mode.
    • "Same fields, huge volume, your own types" = custom NER.
    • "Mask personal data" = PII detection, with a categories filter when policy lists some.

    Five quick revision questions

    1. 1.Which Azure Language feature returns a redacted copy of text?Show

      PII detection.

    2. 2.What does strict true add to a JSON schema?Show

      Every field is required and the reply can't contain extra fields.

    3. 3.What is the first thing to try when a summary lacks required items?Show

      A domain prompt with a checklist and an example.

    4. 4.Which feature learns your own entity types?Show

      Custom NER.

    5. 5.Which Azure Language feature finds people, places and dates?Show

      Named entity recognition.

    Official references

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

    Next up: Sentiment, Tone and Sensitive Content Detection

    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.