Skip to main content
Now that we understand the concepts behind text analysis, let’s take the next step and see how to build applications that use these capabilities. In this article, you’ll learn how client applications connect programmatically to AI models and language services to analyze text. The goal is to move from conceptual understanding to concrete implementation: how developers can call models and language APIs from code, obtain structured results, and integrate those results into an application workflow. We’ll compare two common approaches and show example code for each:
  • Using general-purpose AI models via the OpenAI Python library for flexible, prompt-driven workloads.
  • Using Azure AI Language (Text Analytics) SDK for specialized, operation-based NLP tasks that return consistent, structured outputs.
General-purpose models excel at flexible, prompt-driven workflows. Use Azure AI Language when you need deterministic, structured outputs (e.g., NER, PII detection, healthcare analysis) and production-ready APIs.
A presentation slide titled "Creating Client Applications for Text Analysis" comparing the OpenAI Python Library and the Azure Language SDK. It lists features for each (e.g., flexible prompt-driven applications and multiple NLP tasks for OpenAI, versus consistent structured outputs and prebuilt PII/NER analytics for Azure).
Why choose one over the other?
  • Use a general-purpose model when you need a single, flexible API that can handle many different language tasks via natural-language prompts.
  • Use Azure AI Language when you need predictable, typed outputs (entities, PII labels, sentiment scores) that are easy to validate, store, and process in production pipelines.
Comparison at a glance: Key considerations:
  • General-purpose models are powerful and flexible, but outputs can be non-deterministic. Add validation, confidence checks, or reranking for production scenarios.
  • Azure AI Language operations are designed for consistent, programmatic consumption and are often a better fit for high-volume or compliance-sensitive workloads.
Connecting to a general-purpose model (OpenAI Python library) The client pattern for calling an OpenAI-style model typically follows five steps:
  1. Import the client and helpers.
  2. Load environment variables so secrets are not hard-coded.
  3. Create the client with endpoint and API key.
  4. Send the prompt (request) to the model.
  5. Handle and validate the result in your application.
Example: Sentiment classification using the OpenAI client
Best practices when using general-purpose models
  • Never hard-code API keys. Use environment variables, managed identities, or secret stores.
  • Use temperature, system prompts, or few-shot examples to control output style and consistency.
  • Validate outputs against expected patterns and add fallback logic for unexpected responses.
Do not hard-code API keys in source files. Use environment variables, managed identities, or a secret store such as Azure Key Vault for production applications. See Azure Key Vault overview.
Connecting to Azure AI Language (Text Analytics SDK) Azure AI Language provides operation-specific APIs that return strongly-typed responses for common NLP tasks. The flow is similar to the general-purpose approach but centers on calling explicit operations such as named entity recognition (NER), PII detection, or sentiment analysis. Typical steps:
  1. Import the language client for the operation you need (e.g., TextAnalyticsClient).
  2. Authenticate using AzureKeyCredential or other supported mechanisms (Managed Identity via DefaultAzureCredential is recommended in production).
  3. Create the client with your endpoint and credential.
  4. Submit one or more documents to the target operation.
  5. Iterate the structured results and use their typed properties programmatically.
Example: Named Entity Recognition (NER) with Azure Text Analytics
Why Azure AI Language is suited for production
  • Results come as typed objects (entities, spans, confidence scores), simplifying downstream processing and storage.
  • The SDK exposes multiple specialized operations (PII, opinion mining, healthcare) that map directly to common business needs.
  • Scales well for high-volume workloads and integrates with Azure security and governance services.
Quick developer checklist Summary
  • Choose a general-purpose model when you need flexibility and prompt-driven behaviors that can adapt to many tasks in a single request.
  • Choose Azure AI Language (Text Analytics SDK) when you need consistent, structured outputs for programmatic consumption, compliance, or high-volume production workloads.
Further reading and references This lesson covered both prompt-driven, flexible APIs and operation-based language services, their trade-offs, and practical code patterns to integrate these capabilities into your applications.

Watch Video