Skip to content

Tier by semantic level (VLM and semantic representation / Stage T)

This page continues Tier the response by trust (DataUserVC / Stage T) (§0–§7) and Deliver images and video with tiered access (DataUserVC / Stage T) (§8–§11). It covers converting footage into a semantic intermediate representation and changing the output by the receiver's trust (trust-aware rendering). Section numbers continue from the first page (§12–§13).

What you'll do: Derive new content with VLM inference and face blurring and project it per tier, then run trust-aware rendering on the semantic intermediate representation (SIR)

Prerequisites: §0–§7 of Tier the response by trust (DataUserVC / Stage T) and §8–§11 of Deliver images and video with tiered access (DataUserVC / Stage T)

Keep running: nothing needs to be running. §12.2 starts the publisher, mosquitto and the VLM (Ollama)

What you need: PC + smartphone (iw3ip-wallet), and a publisher started with --profile vlm (Ollama)

Time required: approx. 60–90 min (the first run takes longer because the VLM model has to be downloaded)

Where this page belongs

12. Semantic-level redaction (VLM + face blur)

§1–§11 (the first page, Tier the response by trust (DataUserVC / Stage T), and the second page, Deliver images and video with tiered access (DataUserVC / Stage T)) gate access by dropping media keys — Tier 2 hides video, Tier 1 hides image and video. §12 derives new content from the same source via VLM inference + face blurring (frontal faces in the MVP) and projects those derivatives per tier. This lets Tier 1 receivers get a summary text with private information removed.

Design rationale: see Tiered access design spec, "Tier extension".

12.1 Updated tier definitions

Tier access level Example (score) Derivatives shipped
3 Full full gov + crime + ISO27001 (80) raw image / video + redacted image + full text + summary text
2 Access access enterprise + research + ISO27001 (75) face-blurred image + detailed text (named entities) + summary
1 Summary summary (new) enterprise + unknown purpose + legalCompliance only (50–59) summary text only (PII-redacted, no image)
0 Denied denied unqualified (<50) events only (no image, video, or description)

A new summary value joins the access_level enum: only when the publisher's VLM_BACKEND environment variable is non-empty (set in §12.2), scores 50–59 map to summary. With VLM_BACKEND empty, scores below 60 are still denied, even if Ollama is running under --profile vlm. The /platform/data row schema gains:

Key Content Visible at tier
image_url_redacted URL of an image with faces blurred (frontal faces only in the MVP) 2 + 3
image_cid_redacted IPFS CID of the redacted image (when option C is on) 2 + 3
description_full VLM-generated detailed description (named entities present) 2 + 3
description_summary VLM-generated summary (PII-redacted) 1 + 2 + 3
description_model VLM model id + version (audit) every tier
description_generated_at Inference timestamp (ISO8601) every tier
processing_warnings List of degraded steps (vlm_unavailable, redaction_unavailable) every tier

12.2 Bring up with --profile vlm

VLM and face blur are opt-in. The switch to four tiers happens when the publisher's VLM_BACKEND environment variable is non-empty. --profile vlm only starts the Ollama containers; with VLM_BACKEND empty, §1–§11 keep working under the legacy 3-tier projection.

Set the publisher backends, then bring everything up. The compose file reads these environment variables, so either export them in your shell or write them in .env. Docker on macOS runs the model on the CPU, and llava takes about 3 minutes per inference. The default wait of 180 s is not enough, so extend it with VLM_TIMEOUT_SEC (to use the lighter moondream, also set VLM_MODEL=moondream). With --profile vlm, the Ollama service and vlm-pull, which pulls llava in advance, start together.

cd ~/program/Blockchain_IoT_Marketplace
export VLM_BACKEND=ollama
export IMAGE_REDACTION_BACKEND=opencv
export VLM_TIMEOUT_SEC=600
docker compose -f infra/docker-compose.yml --profile vlm up -d \
  publisher mosquitto vlm vlm-pull

Starting with changed environment variables recreates the publisher container. The claims, ViewerTokens, and event rows kept in memory are cleared, so redo the claims and presentations in §12.4.

Wait for vlm-pull to finish pulling llava (first time only, multi-GB):

docker compose -f infra/docker-compose.yml logs -f vlm-pull

When the line vlm model llava ready appears, exit with Ctrl+C. If you set VLM_MODEL=moondream, the line is vlm model moondream ready.

Check that the publisher is up:

curl -s http://localhost:8080/health | jq .

Expected output:

{"status": "ok", ...}

12.2.1 Publish an event with an image

description_* and image_url_redacted are attached only to rows published after VLM_BACKEND is set. Register the consent and publish an event with an image. In a new terminal, first run cd ~/program/Blockchain_IoT_Marketplace and export HOST_IP='<PC LAN IP>' (see Hands-on). Without --image, the script uses the 16×16 grey image in the course repository. Face blur still runs on this image and image_url_redacted is produced, but the image has no face, so nothing is blurred. To see a face being blurred, optionally add --image '<path to an image with a face>' (a synthetic one, for example). If you ran this script before and the old fixture (a 155-byte JPEG with no image data) is still there, run git pull first; the script then replaces the fixture with the new image automatically.

curl -s -X POST localhost:8080/consents \
  -H 'content-type: application/json' \
  -d @examples/consent_possible_littering.json | jq .status
python3 examples/hands_on/data_user_vc_tiered/provider_with_media.py \
  --base-url http://$HOST_IP:8080

The row lands even if the script times out

/simulate/publish responds only after VLM inference finishes. On a CPU-only PC inference takes tens of seconds to minutes, so the script may exceed its wait time and stop with an error such as TimeoutError (the wait defaults to 600 s and can be changed with the HANDS_ON_HTTP_TIMEOUT environment variable; an older course repository uses 10 s, so run git pull). The publisher keeps processing, and the row is recorded once inference is done. Confirm that a row with raw_topic homeassistant/event/possible_littering and action allow was added:

curl -s localhost:8080/audit/logs \
  | jq '[.[] | select(.raw_topic == "homeassistant/event/possible_littering")][0] | {ts, action, reason}'

LLaVA takes minutes per inference on CPU. If it exceeds VLM_TIMEOUT_SEC (default 180 s), the row gets processing_warnings: ["vlm_unavailable"]. On a CPU-only PC, restart with export VLM_TIMEOUT_SEC=600, or use the lighter moondream (export VLM_MODEL=moondream; see §13.3 for pulling the model and §12.10 for a comparison).

12.3 Four DataUserVC offers

The §2 set extended with a summary-tier profile.

Open each URL in a PC browser and scan the QR code with the wallet.

12.3.a Tier 3 (full) — same as §2a

http://<HOST_IP>:8080/issuer/offer?type=DataUserVC&entity_type=GovernmentOrganization&purpose=CrimeSearch&legal_compliance=true&data_handling_policy=ISO27001&misuse_record=false

12.3.b Tier 2 (access) — same as §2b

http://<HOST_IP>:8080/issuer/offer?type=DataUserVC&entity_type=Enterprise&purpose=Research&legal_compliance=true&data_handling_policy=ISO27001&misuse_record=false
http://<HOST_IP>:8080/issuer/offer?type=DataUserVC&entity_type=Enterprise&purpose=unknown&legal_compliance=true&data_handling_policy=other&misuse_record=false

score = 20 + 5 + 15 + 0 + 10 = 50 -> summary (only when VLM_BACKEND is set)

12.3.d Tier 0 (denied) — same as §2c

With the VLM extension on there are four tiers: summary is Tier 1 and denied is Tier 0. "Tier 1 (denied)" in §2c is the name used with three tiers (extension off) and refers to the same profile. denied is the name of the trustScore verdict. In the current implementation a denied verdict does not reject the purchase report (/marketplace/claim). A PurchaseViewerVC that can view events only (PurchaseViewerVC.event) is issued, and images, video, and descriptions are left out of the response.

http://<HOST_IP>:8080/issuer/offer?type=DataUserVC&entity_type=Enterprise&purpose=Research&legal_compliance=false&data_handling_policy=Other&misuse_record=true

12.4 Four /marketplace/claim calls + /platform/data comparison

Same routine as §3–§4: claim → PurchaseViewerVC → present → ViewerToken → fetch. The rows are the ones published in §12.2.1.

In each claim, put the same attributes as the offer URLs of 12.3.a–d in data_user_attrs, and use a different tx_hash for each claim. The trustScore is what trust_score.py computes, and the tier is the result with VLM_BACKEND set.

Profile tx_hash data_user_attrs trustScore → tier
12.3.a Tier 3 0xdemo-vlm-tier3 {"entityType":"GovernmentOrganization","purpose":"CrimeSearch","legalCompliance":true,"dataHandlingPolicy":"ISO27001","misuseRecord":false} 80 → full
12.3.b Tier 2 0xdemo-vlm-tier2 {"entityType":"Enterprise","purpose":"Research","legalCompliance":true,"dataHandlingPolicy":"ISO27001","misuseRecord":false} 75 → access
12.3.c Tier 1 0xdemo-vlm-tier1 {"entityType":"Enterprise","purpose":"unknown","legalCompliance":true,"dataHandlingPolicy":"other","misuseRecord":false} 50 → summary
12.3.d Tier 0 0xdemo-vlm-tier0 {"entityType":"Enterprise","purpose":"Research","legalCompliance":false,"dataHandlingPolicy":"Other","misuseRecord":true} 25 → denied

For example, the claim for 12.3.c is below. For the other three, change tx_hash and data_user_attrs to the values in the table.

curl -s -X POST localhost:8080/marketplace/claim \
  -H 'content-type: application/json' \
  -d '{
    "merchandise_address": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
    "buyer_eth_addr": "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC",
    "tx_hash": "0xdemo-vlm-tier1",
    "dataset_id": "home/event/possible_littering",
    "data_user_attrs": {"entityType":"Enterprise","purpose":"unknown","legalCompliance":true,"dataHandlingPolicy":"other","misuseRecord":false}
  }' | tee /tmp/claim.json | jq '{claim_id, offer_url}'

If the cards you received in §4 of the first page are still in the wallet, they appear under the same names as the cards you receive here. Presenting an old card shows no VLM descriptions or redacted image. Delete the old cards from the wallet first, or after presenting run docker compose -f infra/docker-compose.yml logs publisher 2>&1 | grep viewer_token_issued | tail -n 1 and check views= in the "message" of the JSON it prints: Tier 3 is event+image+video+image_redacted+description_full+description_summary, Tier 2 is event+image_redacted+description_full+description_summary, Tier 1 is event+description_summary, and Tier 0 is event.

With VLM_BACKEND set:

Profile event image_url video_url image_url_redacted description_full description_summary
12.3.a Tier 3 (full) yes yes yes yes yes yes
12.3.b Tier 2 (access) yes no no yes yes yes
12.3.c Tier 1 (summary) yes no no no no yes
12.3.d Tier 0 (denied) yes (events only) no no no no no

If you ran §12.2.1 with the default grey image, the keys are the same as in this table. However, image_url_redacted has no face, so nothing in it is blurred, and description_* are short sentences about a plain grey image.

With VLM_BACKEND empty the legacy 3-tier projection runs (same as §4; no derivative keys appear). Claim 12.3.c then resolves to denied since summary is used only when VLM_BACKEND is set.

Even for a summary-tier claim, the wallet shows the card under the event-only name (PurchaseViewerVC.event). The issued VC's allowed_views still contains description_summary, so /platform/data returns what the summary tier allows.

12.5 Verifying face blur

Open image_url_redacted from a Tier 2 response in a browser. You should see the same scene as image_url (Tier 3 only) but with faces blurred.

If you ran §12.2.1 with the default grey image, no face is detected, so image_url_redacted shows a grey image that looks the same as the original. To see a face blurred as in the example below, publish the event again in §12.2.1 with --image pointing to an image with a face, and fetch /platform/data for Tier 2 as in §12.4.

Original (image_url, Tier 3 only) Blurred (image_url_redacted, Tier 2+)
pre-redaction post-redaction

Internally the publisher:

  1. fetches the source from /media/<sha>.<ext>
  2. runs OpenCV Haar-cascade face detection
  3. applies a 51×51 Gaussian blur to each face region
  4. re-encodes in the original format
  5. POSTs the result back to its own /media/upload (which dedups + optionally pushes to IPFS)
  6. surfaces the resulting URL/CID as image_url_redacted / image_cid_redacted

The blur runs each time an event is published (not when /platform/data is read). Blurred images made from the same source are not stored twice, thanks to the sha256 dedup in /media/upload.

MVP limitations

The Haar cascade catches frontal faces only. Side profiles, occluded faces, and low-resolution faces pass through. License plates / ID badges / sharp-rectangle screen detection are future work in the spec.

12.6 Inspecting VLM output

Compare description_full (Tier 2/3) against description_summary (Tier 1+) to confirm proper-noun stripping. First present the Tier 3 (12.3.a) PurchaseViewerVC as in §12.4, then set the token= value in the "message" of the publisher's viewer_token_issued log line (docker compose -f infra/docker-compose.yml logs publisher 2>&1 | grep viewer_token_issued | tail -n 1) with export VIEWER_TOKEN_TIER3='<token value>'. The ViewerToken expires after 60 seconds, so right away run the following to fetch every key at Tier 3. The rows of /platform/data are listed oldest first, so .rows[-1] shows the last row (the event you published most recently):

curl -s -H "authorization: Bearer $VIEWER_TOKEN_TIER3" \
     'localhost:8080/platform/data?dataset_id=home/event/possible_littering' \
  | jq '.rows[-1] | {description_full, description_summary, description_model}'

Example output:

{
  "description_full": "John Smith dropped a Coca-Cola bottle near the Hibiya station entrance at around 14:32.",
  "description_summary": "An adult dropped a piece of litter near a public location during the afternoon.",
  "description_model": "ollama/llava"
}

This example is for an image with a person in it. With the default grey image, both are short sentences saying the image is plain grey.

The _full line keeps the person's name, brand, and place. The _summary line collapses to "an adult / public location / afternoon".

Possible redaction leaks

LLaVA-class VLMs are probabilistic; description_summary may structurally still contain PII (e.g. clothing details that re-identify, building names that look generic). The spec records detection as a research TODO (NER diff + PII dictionary). For production, queue Tier 1 outputs for human review.

12.7 Degrade behavior

If either VLM or blur fails, publishing keeps going and processing_warnings[] tells the receiver what was skipped.

To stop the VLM only, stop vlm with:

docker compose -f infra/docker-compose.yml stop vlm

Then publish an event with provider_with_media.py as in §12.2.1. The ViewerToken expires after 60 seconds, so the one you set earlier no longer works. Get a new ViewerToken as in §12.4, then fetch /platform/data. The last row of the response looks like this:

  • processing_warnings contains vlm_unavailable
  • image_url_redacted is still generated, because face blur does not use the VLM (with the default grey image there is no face, so nothing is blurred)
  • the description_* keys are absent

To stop both, stop vlm the same way, then clear the publisher's IMAGE_REDACTION_BACKEND and start it again:

cd ~/program/Blockchain_IoT_Marketplace
docker compose -f infra/docker-compose.yml stop vlm
VLM_BACKEND=ollama VLM_MODEL=llava VLM_TIMEOUT_SEC=600 IMAGE_REDACTION_BACKEND= \
  docker compose -f infra/docker-compose.yml --profile vlm up -d publisher

VLM_BACKEND and the other variables are set at the start of the command so that the publisher restarts with the 4 tiers even in a new terminal where the variables exported in §12.2 are gone. If you used VLM_MODEL=moondream in §12.2, change VLM_MODEL=llava to VLM_MODEL=moondream.

Restarting the publisher clears the claims and rows kept in memory. Publish the event again as in §12.2.1, and redo the claims and presentations in §12.4 to get a new ViewerToken. Fetch /platform/data with that ViewerToken; the last row of the response looks like this:

  • processing_warnings contains vlm_unavailable
  • Tier 2 and Tier 1 receivers get no image keys and no description_* keys, only the event

Clearing IMAGE_REDACTION_BACKEND disables face blur entirely. Nothing is attempted, so no redaction_unavailable appears (that warning is emitted only when a backend such as opencv is set and the blur fails). VLM_BACKEND is still set, so the 4-tier mapping of §12.1 stays in effect; this is not the same as the 3-tier projection with VLM_BACKEND empty.

image_url / video_url always remain visible at Tier 3 even when derivatives are degraded. When an expected key is missing, the receiver can check processing_warnings to see why.

12.8 Relation to §11 (PWA Provider)

Images uploaded through /provider (§11) automatically flow through the VLM pipeline when VLM_BACKEND is set. The provider page itself needs no change; derivative generation is server-side. The receiver-side /viewer shows image_url_redacted with a 🔒 badge when raw keys are dropped, renders description_full / description_summary as parallel green / orange panels, and shows an inline warning banner per row when processing_warnings[] is set (shipped in Blockchain_IoT_Marketplace#48).

12.9 Troubleshooting

Symptom Fix
vlm-pull returns "pull model manifest: file does not exist" The model name or tag does not exist in the Ollama registry. Check the spelling of VLM_MODEL (e.g. llava, llava:7b, moondream). A network failure shows dial tcp ... lookup registry.ollama.ai or connection refused instead. To check reachability, run curl -I https://registry.ollama.ai on the host (any HTTP response means it is reachable)
First /provider/publish times out LLaVA cold start (loading into VRAM) takes 30–60s. Confirm vlm-pull reported "model ready"; subsequent calls are fast
description_full and description_summary come back identical LLaVA may have ignored the prompt difference. docker compose -f infra/docker-compose.yml logs vlm should show two distinct /api/generate calls; if not, check the prompt strings in vlm_client.py
image_url_redacted looks unblurred Haar cascade catches only frontal faces. Side / occluded / small faces pass through — swap in a DNN detector if needed
description_* keys appear with VLM_BACKEND empty Bug — the legacy projection should never emit derivative keys. The regression test test_pipeline_no_injectors_keeps_legacy_envelope covers this; if you see it, file an issue
processing_warnings: ["vlm_unavailable"] keeps firing Ollama not responding or VLM_API_URL wrong. The publisher image has no curl, so check from the publisher with docker compose -f infra/docker-compose.yml exec publisher python -c "import httpx;print(httpx.get('http://vlm:11434/api/version').text)"

12.10 Real-device validation log

Same format as §11.8, recording the VLM + face blur runs on real devices.

Scenario Environment Status Observations
V1 Tier 3 has every key macOS Chrome + Ollama (llava) partial (2026-04-30) Pipeline logs confirm vlm_describe_done full_len=280 summary_len=172 + opencv_blur_faces detected=1. Per-tier /platform/data projection deferred — needs the iPhone OID4VP loop
V2 Tier 2 has redacted + text, no raw image macOS Chrome not verified OID4VP needed; deferred
V3 Tier 1 (summary) is text-only macOS Chrome not verified OID4VP needed; deferred
V4 Face blur visual confirmation StyleGAN2 synthetic face (no real PII) → publish → Tier 2 receiver verified (2026-04-30) OpenCV detected 1 face, applied Gaussian blur (51×51), re-uploaded as a separate file. Face is unrecognizable in the output.
📷 original → redacted
V5 description_full vs summary quality StyleGAN2 sample partial VLM 2-stage prompting completed (full_len=280, summary_len=172). Actual text diff requires ViewerToken-based fetch; deferred
V6 VLM-down degrade timeout 60s effectively triggered vlm_unavailable verified (2026-04-30) vlm describe failed: ollama call failed: timed out → processing_warnings: ["vlm_unavailable"] emitted; image_url_redacted still generated. The timeout was later extended (item 2 in the table below), but the basic degrade behavior is confirmed
V7 Redaction-leak survey large sample 🔬 research Spec's post-check implementation prerequisite; not started in this validation pass

Bugs / constraints surfaced during V1–V6

Three operational findings emerged during this pass:

# Symptom Cause / Resolution
1 /provider/publish followed by vlm describe failed: ollama call failed: timed out CPU LLaVA-7B inference takes ~186s per stage (even on a small image). describe() needs 2 stages → ~6 min total
2 The original default VLM_TIMEOUT_SEC=60 couldn't complete Blockchain_IoT_Marketplace#45 bumps to 180s; CPU setups need VLM_TIMEOUT_SEC=600
3 LLaVA-7B on CPU is impractical for hands-on workshops We recommend a smaller model (bakllava, moondream), a GPU environment, or an external API

moondream re-test (2026-04-30 addendum)

Pulled moondream (1.7 GB, ~1/3 of llava) and re-ran the same pipeline:

Metric llava moondream
Model size 4.7 GB 1.7 GB
describe() time on CPU ~6 min ~21 s – 5 min (depends on prompt + cold/warm)
Current long two-stage prompts Long output (full_len=280, summary_len=172) Fragments only (full_len=3, summary_len=10)
Simple prompt ("Describe this image.") Works but verbose High quality: "A man with a beard and glasses... blurred green landscape"

Finding: a small VLM (moondream) is much faster but does not respond well to the current long 2-stage prompts. Either tune prompts per-backend (a prompts: {model -> str} dict in vlm_client.py) or unify all backends on shorter prompts.

Short-prompt unification trades off redaction-strength expressiveness, so we chose a per-model prompt table. This is now implemented: _PROMPT_TABLE in publisher/app/vlm_client.py picks short prompts (moondream, bakllava) or the long ones (llava) by model-name prefix. Models not in the table use the long prompts.

V4 visual comparison

Original (synthetic) OpenCV Haar-cascade blurred
original redacted
Face details (eyes, nose, mouth) clearly visible Central rectangular face region completely Gaussian-blurred; hair, ears, beard, and background unchanged

The image is a StyleGAN2 synthetic face — no real-world PII involved.

The implementation is verified at unit-test level (155/155 pass) in Blockchain_IoT_Marketplace#44, with the timeout fix in #45.

13. Semantic intermediate representation + trust-aware rendering

§12 stops at "drop or blur image keys per access_level". §13 takes the next step: replace the implicit frame -> VLM -> output path with an explicit four-layer pipeline:

frame -> SIR -> trust policy -> trust-aware renderer -> output

Privacy-sensitive regions (faces, text, screens, whiteboards, documents, name tags, ID cards, license plates, plus unknown_sensitive) are structured as bounding boxes in the SIR. The trust policy maps a ViewerTrustLevel × SIR pair to allowed output kinds, and the renderer is the only place that ever combines the source bytes with the policy decision. Low-trust receivers cannot reach raw bytes by construction (fail-closed by design).

For the detailed design rationale, see Tiered access design spec (the spec has no chapter for §13 yet; one is planned).

13.1 Architecture

flowchart TB
  U["iPhone Safari /provider<br>uploads frames as in §11.3"]
  subgraph SA["publisher SemanticAnalyzer: /semantic/analyze"]
    SA1["MockSemanticAnalyzer<br>(test / MVP)"]
    SA2["VisionSemanticAnalyzer<br>(OpenCV Haar + MSER)"]
    SA3["Apple Vision / Core ML / VLM<br>(future)"]
  end
  SIR["Semantic Intermediate Representation (SIR) JSON"]
  TPE["TrustPolicyEngine<br>/semantic/render or /semantic/render_url"]
  TAR["TrustAwareRenderer"]
  OUT["Viewer Output"]
  U -->|"POST /media/upload"| SA
  SA --> SIR
  SIR -->|"normalized bbox + sensitive_regions[] + events[] +<br>privacy_risk_score + analyzer_version"| TPE
  TPE -->|"ViewerTrustLevel ∈ {anonymous,low,medium,high,owner,admin}<br>-> DisclosurePolicy (allowed_outputs + mask_regions + audit_required)"| TAR
  TAR -->|"textSummary / eventList / redactedImage / lowResolutionImage /<br>maskedVideoFrame / originalFrame"| OUT

Each layer can be tested independently. Even if the policy decision or the VLM output is wrong, the layer structure guarantees that the pipeline fails toward the safe side (hiding).

13.2 Trust × output matrix

Mapping of ViewerTrustLevel (6 levels) to OutputKind (6 kinds):

Level textSummary eventList redactedImage lowResolutionImage maskedVideoFrame originalFrame
anonymous ✗ ✓ ✗ ✗ ✗ ✗
low ✓ ✓ ✗ ✗ ✗ ✗
medium ✓ ✓ ✓ ✓ ✗ ✗
high ✓ ✓ ✓ ✓ ✓ ✗
owner ✓ ✓ ✓ ✓ ✓ ✓ (audit)
admin ✓ ✓ ✓ ✓ ✓ ✓ (audit)

unknown_sensitive is always masked at HIGH and below unless SEMANTIC_ALLOW_UNKNOWN_AT_HIGH=true is explicitly set.

13.3 Bring up

Add SEMANTIC_ANALYZER_BACKEND to the existing VLM-tier compose run. vlm-pull in §12.2 pulls only the VLM_MODEL default (llava). This step uses moondream, so pull it first. If you stopped vlm in §12.7, start it again first:

cd ~/program/Blockchain_IoT_Marketplace
docker compose -f infra/docker-compose.yml --profile vlm up -d vlm
docker compose -f infra/docker-compose.yml --profile vlm exec vlm ollama pull moondream
SEMANTIC_ANALYZER_BACKEND=vision \
  VLM_BACKEND=ollama VLM_MODEL=moondream IMAGE_REDACTION_BACKEND=opencv \
  docker compose -f infra/docker-compose.yml --profile vlm up -d publisher

Starting with changed environment variables recreates the publisher container. The claims, ViewerTokens, and event rows kept in memory are cleared, so before §13.5 publish the event again as in §12.2.1 and redo the claims and presentations in §12.4.

Env var Value Effect
SEMANTIC_ANALYZER_BACKEND empty / stub MockSemanticAnalyzer (deterministic, always 3 fixed regions)
SEMANTIC_ANALYZER_BACKEND vision OpenCV Haar cascade + MSER
SEMANTIC_ALLOW_UNKNOWN_AT_HIGH true Let HIGH viewers see unknown_sensitive

13.4 /provider §1.5 "Run analysis" panel

Right after uploading media as in §11.3, a "1.5 意味的中間表現を確認" (check the semantic intermediate representation) section appears on the /provider page ("§1.5" is a section number inside that page, not a section of this document). It is a UI for a dry run: checking how receivers will see the data before you press Publish.

  1. When the upload completes, the "分析を実行" (run analysis) button is enabled
  2. Pressing it calls POST /semantic/analyze to get the SIR
  3. The detected sensitive_regions are overlaid on the source image as red bounding boxes
  4. Four cards (anonymous / low / medium / high) preview how each trust level sees the data
  5. granted_kinds, text_summary, and the masked image inline when the policy allows it
  6. Before the real Publish, the provider can check on the device "what a medium receiver will see"

This check lets you catch analyzer misses and over-detection before the event is published. It runs independently of the Publish button, so you can check, skip Publish, and try again.

13.5 /viewer 🔬 toggle — trust-aware rendering

The receiver-side /viewer gains a "🔬 意味的レンダリングを使う (実験)" (use semantic rendering, experimental) checkbox at the top. Off (default) shows the same legacy tier projection as §10. On works as follows:

  1. On page load, the trust level is derived from allowed_views in /platform/data
    video         → high
    image | image_redacted → medium
    description_* → low
    event only / unknown → anonymous (fail-closed)
    
  2. Each row with an image calls POST /semantic/render_url (rows without an image, such as Tier 1/0, show text only), and the server runs fetch + analyze + policy + render in one round trip
  3. The result is shown:
  4. [<level>] kinds: redactedImage + textSummary + eventList
  5. the permitted image_b64 inline as an <img>
  6. text_summary, event_list, the audit_required banner, and the policy rationale (debug)

The toggle state is saved in localStorage, so the selection survives a reload. With the toggle off, behavior is exactly the same as before, so the steps up to §12 are not affected.

13.6 Fail-closed sites

Site Behavior
_coerce_trust_level() unknown value / None → ANONYMOUS
TrustPolicyEngine.evaluate() privacy_risk_score >= 0.9 strips image kinds
TrustPolicyEngine.evaluate_safe() internal exception → allowed_outputs=frozenset() (empty)
_compute_mask_plan() masks face/text/screen/whiteboard/document/id_card/name_tag/license_plate/unknown_sensitive at HIGH and below (only unknown_sensitive at HIGH can be unmasked with SEMANTIC_ALLOW_UNKNOWN_AT_HIGH=true)
TrustAwareRenderer.render() double-checks trust_level in (OWNER, ADMIN) for ORIGINAL_FRAME
_render_masked() cv2 / decode / encode failure → text fallback
SemanticIntermediateRepresentation.empty() represents an analyzer failure as a fail-closed state with privacy_risk_score=1.0
/semantic/analyze on failure returns an empty() SIR (never returns raw bytes)
/semantic/render_url URL fetch failure → empty() SIR + text-only

13.7 Server-side audit log

/semantic/render and /semantic/render_url add a row to audit_log when either of the following holds:

  • The policy returned audit_required=True (OWNER / ADMIN tier)
  • The renderer actually returned image_bytes (any trust level)

Fields recorded in the audit row:

Field Value
ts UTC ISO8601
action semantic/render or semantic/render_url
subject_did sir.source_device_id
dataset_id empty string (the current implementation does not set it)
purpose semantic_render
reason trust=<level>;kinds=<list>;image=yes|no;audit_required=<bool>;rationale=<policy>
message_hash sir.frame_id
raw_topic same value as action
presentation_verified owner_or_admin or policy_only

Not recorded: the source frame bytes, the base64-encoded rendered image, and any face encoding / person name derived from the SIR. image_url is not in the audit row either (the row has no field for a URL).

Calls with audit_required false that return no image are not written to the audit table, whatever the trust level (so that the audit table records only actual disclosures).

13.8 API reference

POST /semantic/analyze

  • Input: multipart file field + source_device_id form value
  • Output: SIR JSON ({frame_id, source_device_id, captured_at, scene_summary, objects, people, sensitive_regions, events, privacy_risk_score, analyzer_version})
  • Security: the input bytes are never included in the response. On analyzer failure it returns SemanticIntermediateRepresentation.empty().

POST /semantic/render

  • Input: JSON {trust_level?: string, sir: object, image_url?: string}
  • Output: {trust_level, granted_kinds[], text_summary, event_list[], rationale, audit_required, image_b64?, image_content_type?}
  • Security: an unknown trust_level is treated as ANONYMOUS. The publisher fetches image_url as given (with no check), so pass only the publisher's own /media/… URLs. Low-trust receivers never get image_b64.

POST /semantic/render_url

  • Input: JSON {trust_level?: string, image_url: string, source_device_id?: string}
  • Output: same as /semantic/render
  • Behavior: the server runs fetch + analyze + render in one call. If fetch or analyze fails, it responds fail-closed using an empty() SIR.

13.9 Relation to §12 VLM tier

Aspect §12 VLM tier §13 semantic pipeline
Trust derivation allowed_views computed from data_user_attrs in /marketplace/claim and baked into the PurchaseViewerVC derived at runtime from allowed_views; legacy default kept
Derivative shape text + face-blurred image structured SIR (bbox + sensitive_regions + events)
Mask granularity face only (image_url_redacted) face + text + screen + whiteboard + document + id_card + name_tag + plate + unknown_sensitive
Receiver toggle fixed at claim mint runtime via /viewer 🔬 toggle
Failure mode processing_warnings: ["vlm_unavailable"] empty() SIR + text-only fallback
Audit per-component (image_redactor / vlm_client) unified hook in /semantic/render*

The two coexist. The 🔬 toggle leaves the legacy Stage T projection intact; it merely offers an opt-in alternative path.

13.10 Real-device validation log

Recorded in the same format as §11.8 / §12.10.

Scenario Environment Status Verification point
S1 /provider §1.5 panel iPhone Safari (real photo) verified (2026-04-30) Photo captured on iPhone → uploaded to /provider → §1.5 "分析を実行" → analyzer=vision-opencv detected face (conf 0.85) + unknown_sensitive (0.50). Red bbox overlay shown on image, privacy_risk_score=0.90, 4-tier preview cards (anonymous / low / medium / high) all rendered correctly.
📷 S1 screenshot
S2 /viewer 🔬 toggle iPhone Safari + Tier 3 PVC verified (2026-04-30) Tier 3 PVC (PurchaseViewerVC.full, tier=event+image+video+image_redacted+description_full+...) issued and presented on iPhone Safari /viewer. Toggling 🔬 on a single row: OFF → legacy display with raw photo + vlm_unavailable warning. ON → trust-aware via /semantic/render_url: derived trust level: high, [high] kinds: textSummary + eventList, "1人の人物 + 2件のセンシティブ領域" / "person_detected" text only, raw photo suppressed.
📷 toggle OFF / toggle ON
S3 OWNER audit log publisher only (curl) verified (2026-04-30) OWNER trust on /semantic/render_url returned image_b64 + every kind, and /audit/logs got a semantic/render_url row (trust=owner;kinds=textSummary+redactedImage+eventList+originalFrame+maskedVideoFrame+lowResolutionImage;image=yes;audit_required=True)
S4 Vision analyzer face detection publisher (SEMANTIC_ANALYZER_BACKEND=vision) verified (2026-04-30) Synthetic face image → /semantic/analyze returns SIR with face (conf 0.85, bbox x=0.14, y=0.19, w=0.70, h=0.70) + unknown_sensitive (from MSER). privacy_risk_score=0.9 (face 0.4 + unknown 0.5)
S5 cv2-missing fail-closed publisher (sys.modules['cv2']=None simulated) verified (2026-04-30) With cv2 / numpy stubbed out, VisionSemanticAnalyzer.analyze() raises SemanticAnalyzerError("vision backend requires cv2 + numpy"). Route demotes to SemanticIntermediateRepresentation.empty() (objects=0, sensitive=0, events=0, privacy_risk_score=1.0). For trust=anonymous/low/medium/high the renderer drops every image kind (high_risk_score(1.00)>=ceiling(0.9); image kinds dropped) and returns textSummary + eventList only. OWNER alone retains image_bytes via the audit_required path (expected).

Implementation: Blockchain_IoT_Marketplace#49 (pipeline) + #50 (/provider §1.5) + #51 (/viewer 🔬) + #52 (audit hook). Unit tests at 190/190 pass.

Next steps

Next is the second half of 2.5, Prove where an image came from (C2PA / Stage P). You attach C2PA provenance to an image and sign it.

To go back to an earlier page: