Building a Lightweight Vision Application
This lesson assembles the pieces into a lightweight Python application that analyzes images with a deployed multimodal model and returns structured results, and explains when other Foundry services fit better.
Learning outcomes
After completing this lesson, you will be able to:
- Describe the four steps of a lightweight vision application.
- Choose between a multimodal prompt, Azure Vision and Azure Content Understanding.
- Write effective instructions to send with an image.
Structure of the application
A lightweight vision application has four steps. It creates an AIProjectClient with DefaultAzureCredential and gets an OpenAI client. It reads each image file and encodes it as a base64 data URL. It sends a request with an instruction and the image to the multimodal deployment, using structured outputs when the application needs fields. And it prints, stores or acts on the result.
import base64
from typing import Literal
from pydantic import BaseModel
class Inspection(BaseModel):
item: str
condition: Literal["new", "used", "damaged"]
visible_defects: list[str]
def inspect(path):
b64 = base64.b64encode(open(path, "rb").read()).decode()
r = openai.responses.parse(model="gpt-5.4-mini", text_format=Inspection,
instructions="Inspect the returned item in the photo. List only defects you can see.",
input=[{"role": "user", "content": [
{"type": "input_image", "image_url": f"data:image/jpeg;base64,{b64}"}]}])
return r.output_parsed
print(inspect("return_0412.jpg"))Build a vision client
Other vision services
A multimodal prompt is flexible but its output can vary. Azure Vision in Foundry Tools provides prebuilt image analysis, such as captions, tags, object detection and OCR, with fixed output formats. Azure Content Understanding applies a field schema to images consistently, with confidence scores, which suits high-volume extraction pipelines. Choose by the requirement: conversational or custom questions suit a multimodal model; the same typed fields from thousands of images suit Content Understanding.
Choose the vision service
Writing effective image instructions
The quality of a multimodal model's answer depends heavily on the instruction sent with the image. A good instruction states exactly what to look for and how to answer, for example List each product visible on the shelf and say whether its price label is visible rather than Describe this image. It also tells the model what to do when the information is not visible, such as answering not visible rather than guessing.
When the application needs values it can process, the instruction is combined with structured outputs that define the fields and their types. The application is then tested with a range of real images, including poor lighting, unusual angles and images that do not contain the expected objects, to check that the results are reliable before it is used widely.
Better image instructions
Completing a vision client
A developer's script sends input="Describe this image" and the file path "photo.jpg" in the text, and the model replies that it cannot see any image.
The model received only text. The script must read the file, base64-encode it and send it as an input_image content part with a data URL, together with an input_text part for the instruction. The deployment must also be a multimodal model that accepts images.
Which service suits prebuilt captions, tags and OCR?
Show answer
Azure Vision. Content Understanding suits consistent typed fields at scale.
Exam Tips
Remember for the exam
- A vision client reads, encodes and sends the image with the instruction in one user message.
- Structured outputs turn visual analysis into fields for code.
- Consistent typed fields at scale: Content Understanding. Prebuilt captions, tags and OCR: Azure Vision.