Catalogue / content-understanding-python
content-understanding-python
Older skill: source not recordedSignedWrite and debug Python for the azure-ai-contentunderstanding package, which sends documents, images, audio and video to an Azure Content Understanding resource and returns markdown, timed transcript phrases, key frames and custom-schema fields. Covers the sync and async clients, prebuilt and custom…--- name: content-understanding-python description: > Write and debug Python for the azure-ai-contentunderstanding package, which sends documents, images, audio and video to an Azure Content Understanding resource and returns markdown, timed transcript phrases, key frames and custom-schema fields. Covers the sync and async clients, prebuilt and custom analyzers, long-running job polling, result navigation and analyzer lifecycle. Use when the user explicitly names Azure Content Understanding, the azure-ai-contentunderstanding package, ContentUnderstandingClient or begin_analyze and wants PDFs, Office files, photos, recordings or video processed by that specific service, including for indexing, search or RAG built on Azure Content Understanding. Not for Azure Document Intelligence, Azure Speech or Azure OpenAI, the raw REST endpoint, non-Azure extraction tools, or languages other than Python. license: MIT ---
Azure Content Understanding, driven from Python
When the user is on Azure Content Understanding and wants markdown, timed speech, key frames or named data fields pulled out of PDFs, Office files, images, recordings or video, write code for the azure-ai-contentunderstanding package. Every extraction follows one arc — submit a job, let the SDK wait it out, read the structured answer — and every submission carries the user's media up to their Azure resource, so approvals come before anything else.
Get a yes before anything leaves the machine
Three operations are yours to code but not yours to start:
- Submitting media —
begin_analyze(analyzer_id, inputs)hands the referenced file or URL to the Azure resource for processing. State the analyzer id and the exact source location, then wait for a clear go-ahead each time, whoever owns the material and however public it is. An approval covering a named batch of sources carries through the conversation; any source outside that batch, or any new analyzer id, restarts the ask. - Creating an analyzer —
create_analyzer(analyzer_id, analyzer)writes a definition onto the resource that everyone with access to it can see and run. Confirm the id and summarize the field schema with the user before the call. - Deleting an analyzer —
delete_analyzer(analyzer_id)is permanent and removes the analyzer for every user of the resource. Say the exact id back in your reply and proceed only once the user confirms that precise id.
list_analyzers() and get_analyzer(analyzer_id) only read and need no gate.
Wiring up
pip install azure-ai-contentunderstanding
Set the resource address once in the environment:
CONTENTUNDERSTANDING_ENDPOINT=https://cu-atlas-42.cognitiveservices.azure.com/
Build the synchronous client:
import os
from azure.ai.contentunderstanding import ContentUnderstandingClient
from azure.identity import DefaultAzureCredential
client = ContentUnderstandingClient(
endpoint=os.environ["CONTENTUNDERSTANDING_ENDPOINT"],
credential=DefaultAzureCredential(),
)Always read the endpoint from the environment and always pass a credential. DefaultAzureCredential finds the right identity on its own, so no key ever has to appear in your code — do not paste endpoint URLs, key strings or key credentials into source.
First decision: which analyzer
Match the user's goal to an id before writing any call:
| The user wants | Analyzer id | Where the answer lands | |---|---|---| | A PDF, letter or Office file as markdown | prebuilt-documentSearch | contents[0].markdown | | A photo, scan or diagram described as markdown | prebuilt-imageSearch | contents[0].markdown | | A recording transcribed with timestamps | prebuilt-audioSearch | transcript_phrases | | A video's speech, key frames and summary | prebuilt-videoSearch | transcript_phrases and key_frames | | Standard invoice fields | prebuilt-invoice | result.fields | | Domain-specific named fields | a custom analyzer (below) | result.fields |
Copy the ids character for character — they are camelCase, and hyphenated spellings do not exist on the service and are refused. Choose a custom analyzer only when the prebuilts lack fields particular to the user's world; for plain text, transcription or frames, the prebuilts are the shorter road.
One call pattern for every media type
begin_analyze is the only submission method. It takes an analyzer id and a list of AnalyzeInput wrappers and returns a poller; poller.result() blocks until the service finishes — minutes is normal for audio and video — and yields an AnalyzeResult. One input means the answer sits at contents[0].
from azure.ai.contentunderstanding.models import AnalyzeInput
# this exact URL was approved earlier in the conversation
poller = client.begin_analyze(
analyzer_id="prebuilt-documentSearch",
inputs=[AnalyzeInput(url="https://cdn.example.net/manuals/pump-maintenance-r7.pdf")],
)
manual = poller.result().contents[0]
print(f"{len(manual.markdown)} characters of markdown")If the user holds both a hosted URL and local bytes for the same file, submit the URL and let the service fetch it.
Reading the answer
Each entry in contents is a MediaContent subclass carrying shared metadata and the markdown rendering; the specifics depend on kind, so branch on the discriminator before touching type-specific attributes:
| Class | Comes from | Adds | |---|---|---| | DocumentContent | PDFs, Office files, images | pages, tables, figures, paragraphs, start_page_number | | AudioVisualContent | audio and video | transcript_phrases (per phrase text, start_time, end_time); key_frames (per frame time, description) on video |
from azure.ai.contentunderstanding.models import DocumentContent, MediaContentKind
entry = manual
if entry.kind == MediaContentKind.DOCUMENT:
doc: DocumentContent = entry
print(f"document begins at page {doc.start_page_number}")Import model classes from azure.ai.contentunderstanding.models — AnalyzeInput, AnalyzeResult, MediaContentKind, DocumentContent, AudioVisualContent.
Named fields: the custom-analyzer route
When the user names fields no prebuilt returns, define a schema once, create it (gated), then run it against files (each submission gated separately). Field types available in the schema: string, number, object with nested properties, and array with items.
schema = {
"description": "Reads booking facts from ferry tickets",
"base_analyzer_id": "prebuilt-documentSearch",
"field_schema": {
"fields": {
"route_code": {"type": "string"},
"fare_total": {"type": "number"},
"sailing": {
"type": "object",
"properties": {
"vessel": {"type": "string"},
"departs_at": {"type": "string"},
},
},
"passengers": {"type": "array", "items": {"type": "string"}},
}
},
}
# only after the user confirms the id "ferry-ticket-reader" and this schema
client.create_analyzer(analyzer_id="ferry-ticket-reader", analyzer=schema)
# a separate approval covers the ticket itself
poller = client.begin_analyze(
analyzer_id="ferry-ticket-reader",
inputs=[AnalyzeInput(url="https://cdn.example.net/tickets/booking-7741.pdf")],
)
ticket = poller.result()
print(ticket.fields["route_code"], ticket.fields["fare_total"], len(ticket.fields["passengers"]))Extracted values arrive on result.fields as a mapping keyed by the names you declared.
Housekeeping on existing analyzers
Before creating anything, the read-only listing doubles as a collision check:
taken = {a.analyzer_id for a in client.list_analyzers()}
print("ferry-ticket-reader" in taken)
if "ferry-ticket-reader" in taken:
definition = client.get_analyzer("ferry-ticket-reader")Listed items expose analyzer_id and description. Deletion is the irreversible corner of this skill — it runs only after the confirmation ritual above, and the call takes nothing but the id.
Many sources at once
For throughput, switch to the async client from the .aio subpackage, pair it with the async credential, open it as a context manager, and await both stages. The same approval rule covers the whole batch: name every source up front.
import asyncio
import os
from azure.ai.contentunderstanding.aio import ContentUnderstandingClient
from azure.ai.contentunderstanding.models import AnalyzeInput
from azure.identity.aio import DefaultAzureCredential
async def headline(url: str) -> str:
async with ContentUnderstandingClient(
endpoint=os.environ["CONTENTUNDERSTANDING_ENDPOINT"],
credential=DefaultAzureCredential(),
) as client:
poller = await client.begin_analyze(
analyzer_id="prebuilt-documentSearch",
inputs=[AnalyzeInput(url=url)],
)
text = (await poller.result()).contents[0].markdown
return text.splitlines()[0] if text else ""
async def main() -> None:
# both revisions approved earlier in this conversation
urls = [
"https://cdn.example.net/manuals/pump-maintenance-r7.pdf",
"https://cdn.example.net/manuals/pump-maintenance-r8.pdf",
]
print(await asyncio.gather(*(headline(u) for u in urls)))
asyncio.run(main())Runtime rejections to design around
| Fails at | The mistake | Write instead | |---|---|---| | Import | pulling the client from the models module | root package, or .aio for async | | Credentials | sync client handed the aio credential, or the reverse | azure.identity.DefaultAzureCredential for sync; azure.identity.aio.DefaultAzureCredential for async | | Method | per-media begin methods or dict-shaped request bodies — not part of this surface | only begin_analyze(analyzer_id=..., inputs=[...]) | | Arguments | a bare source URL keyword on the call itself | inputs=[AnalyzeInput(url=...)] | | Analyzer id | hyphenated approximations of the prebuilt names | the exact camelCase ids in the table above | | Results | reading contents straight off the poller | the poller is not the result — call .result() first | | Client setup | pasted endpoint, a key string in code, or no credential at all | environment endpoint plus DefaultAzureCredential |
Two hard rules close the list: do not run a submission, a creation or a deletion without the explicit confirmation described above, and do not stretch this skill to Azure Document Intelligence, Azure Speech, Azure OpenAI or the raw REST surface.
Scope and lineage
The signatures here match azure-ai-contentunderstanding 1.0.0b1, a beta from the azure-sdk-for-python repository; betas drift, so re-verify them if the user upgrades. This skill does not cover languages other than Python. It is an independent rewrite of an MIT-licensed community skill for the same package, and that licence carries over.
| File | Size | SHA-256 |
|---|---|---|
| SKILL.md | 11.0 kB | 6bf3803139eb |
| THIRD_PARTY_NOTICES.md | 1.4 kB | 34f8b822e446 |
| examples.json | 2.5 kB | 8c4e935aa4c3 |
Published verbatim from the pinned commit. Nothing is rewritten.
| Version | Pinned commit | Signed | |
|---|---|---|---|
| 1.0.0 Current | Not recorded | 10 Oct 2026 |
Locking a skill to one version needs Pro.