5.1.1. Building a Text Analysis Application
💡 First Principle: To analyze text with a generative model, you describe the analysis you want in the prompt and let the model return the result — ideally in a structured format you specify. The model is the engine; your prompt defines the task (sentiment, entities, keywords, summary) and the output shape.
The two-client pattern from Phase 4 carries over unchanged; only the input differs. You ask for a specific analysis and, for anything a program will consume, request a structured format like JSON:
response = openai_client.responses.create(
model="gpt-5.2", # your deployment name
input="Classify the sentiment of this review as positive, negative, "
"or neutral and return only that word: 'The food was cold and slow.'",
)
print(response.output_text) # -> negative
For higher-volume or specialized needs, Azure also offers dedicated language capabilities, but at fundamentals level the key insight is that one deployed generative model can perform keyword extraction, entity detection, sentiment analysis, and summarization just by varying the prompt.
⚠️ Exam Trap: If you need the output to feed another program (not a human), ask the model for a structured format and use a low temperature for consistency. Free-form prose at high temperature is hard to parse reliably — a common wrong setup in exam scenarios.
Reflection Question: You want sentiment results you can store in a database column. What two things should your prompt and configuration ensure about the output?