Analyzing Text Reliably with Generative Models
This lesson explains how generative models analyze text from a prompt, including analysis that no prebuilt feature offers, how to make that analysis reliable, and when to combine it with Azure Language.
Learning outcomes
After completing this lesson, you will be able to:
- Write reliable analysis prompts.
- Explain how structured outputs constrain a response to a JSON schema.
- Choose between, or combine, Azure Language and a generative model.
Prompting for analysis
A model can classify, extract, summarize and judge tone when instructed. Reliable analysis prompts follow the prompt engineering techniques: precise instructions, the allowed labels or fields, delimiters around the text, a few examples and low randomness. Because the model's general language understanding is broad, a single prompt can return several results at once, such as a summary, the product mentioned, a custom category and whether a follow-up is needed.
Structured outputs
When code processes the result, the response must have a predictable shape. Structured outputs supply a JSON schema with the request, and the model's output is constrained to match it, including enumerations of allowed labels. In Python, the Responses API's responses.parse() accepts a Pydantic model as text_format and returns a parsed object.
from typing import Literal
from pydantic import BaseModel
class Review(BaseModel):
product: str
topic: Literal["quality", "delivery", "price", "support", "other"]
needs_follow_up: bool
r = openai.responses.parse(model="gpt-5.4-mini", text_format=Review,
instructions="Extract the fields from the product review.",
input="My order arrived two weeks late and nobody answered my emails.")
print(r.output_parsed)Predictable output from a model
Choosing and combining approaches
Azure Language gives the same result every time, with calibrated confidence scores and character offsets, at a per-text price and with no prompt to maintain. A generative model gives flexible, custom analysis but needs careful prompting and testing, and its output can vary. Applications often combine them, for example by redacting PII with Azure Language before the text reaches the model, or by using prebuilt sentiment for dashboards and a model for custom categories.
The following table recaps the choice.
| Requirement | Better fit |
|---|---|
| Standard sentiment, key phrases or entities with scores | Azure Language |
| Redaction with entity categories and offsets | Azure Language PII detection |
| Company-specific categories or fields | Generative model with structured outputs |
| Nuanced tone or intent, such as sarcasm or urgency | Generative model |
| Free-form summary in a custom format | Generative model |
The following diagram shows a combined design and the strengths of each approach.

Azure Language or a model?
A hybrid pipeline
An insurer wants each claim email (1) stripped of personal data before analysis and (2) assigned one of the insurer's 12 claim types, with a one-sentence summary, stored as JSON.
Step (1) uses Azure Language PII detection, whose redacted text is then sent to a generative model for step (2), with a JSON schema whose enum lists the 12 claim types and a summary field. Sending the raw email to the model would expose personal data unnecessarily, and prebuilt Azure Language features do not know the insurer's claim types.
When is a generative model better than Azure Language for text analysis?
Show answer
For custom labels, fields and summaries that Azure Language's standard features do not provide.
Exam Tips
Remember for the exam
- Generative models handle custom labels, fields and summaries.
- Structured outputs with a JSON schema make model output parseable.
- Combine: Azure Language for standard analysis and redaction, a model for custom analysis.