Claude requests can use typed content blocks, allowing an application to provide text and supported visual or document inputs. Multimodal input is useful for tasks such as extracting information from a form, comparing an image with a design rule, or summarizing a supplied document. It does not remove the need for input validation, privacy review, or human verification of high-impact claims.
Files and images are untrusted input. Validate content type and size, scan uploads where appropriate, strip or avoid unnecessary metadata, enforce tenant access, and record the source that supported each extracted field.
| Moment | Question | Owner |
|---|---|---|
| Before upload | May this signed-in customer submit and access this file? | Your application and storage policy |
| Before model call | Is this an allowed, bounded, safely stored file? | Your upload validation |
| After extraction | Do the extracted totals and identifiers make business sense? | Deterministic validation or a reviewer |
A message content value can be a string or an ordered array of typed blocks. This lets text describe the task while an image or document block supplies source material. Preserve ordering: put task instructions before a clearly labeled source block and do not rely on implicit visual context.
Use supported formats and limits from current official documentation. These details change, so production validation should be configuration-driven and reviewed regularly.
Upload handling belongs in your application before a model request. Confirm the user may access the file, use file signatures rather than only a filename extension, and keep uploads in private storage. Decide whether your retention policy permits sending the data to an external service.
Never use model output to decide that an unsafe or unrelated file is acceptable. Security checks must run before invocation.
Ask for a typed list of extracted facts, each with the source page, region, or quoted text where the interface supports it. For a receipt, request merchant, date, currency, and total as separate fields with an `uncertain` state.
Extraction is not proof. Reconcile monetary totals, IDs, dates, and policy-sensitive details with deterministic validation or a human review queue.
Use a review threshold based on business impact, not an arbitrary confidence score. A draft alt text can be automatically published after safety checks; a tax document field or medical fact needs domain-specific verification.
Include an explicit “cannot determine” path. This produces safer automation and better evaluation data than forcing an answer for every file.
The code that receives a receipt or image should decide whether the file is allowed. This check belongs before storage, before model invocation, and before any extraction result is used.
Once a file passes validation, ask for a narrow extraction result. For a receipt, that might be merchant, date, total, currency, and an uncertainty flag—not a free-form summary.
This example shows an application-level allow list. A production handler should also inspect file signatures, isolate storage, and enforce per-user authorization.
ALLOWED_TYPES = {"image/png", "image/jpeg", "application/pdf"}
MAX_BYTES = 8 * 1024 * 1024
def validate_upload(content_type: str, size: int, owner_matches: bool) -> str:
if not owner_matches:
return "denied"
if content_type not in ALLOWED_TYPES or size > MAX_BYTES:
return "rejected"
return "accepted"
print(validate_upload("image/png", 1000, True))
accepted
Model output must satisfy the same validation as any other input before it is saved.
from decimal import Decimal, InvalidOperation
def parse_amount(value: str) -> Decimal | None:
try:
amount = Decimal(value)
except InvalidOperation:
return None
return amount if amount >= 0 else None
print(parse_amount("149.50"))
149.50
The model is not a file-security scanner. Accept only file types your feature deliberately supports.
ALLOWED_TYPES = {"image/jpeg", "image/png", "application/pdf"}
def upload_allowed(mime_type: str, size_bytes: int) -> bool:
return mime_type in ALLOWED_TYPES and 0 < size_bytes <= 5_000_000
print(upload_allowed("image/png", 1200))
True
A deterministic check can catch an obvious mismatch after extraction.
def receipt_needs_review(total: float, line_items: list[float]) -> bool:
return round(total, 2) != round(sum(line_items), 2)
print(receipt_needs_review(19.99, [9.99, 10.00]))
False
Use a file your product already handles
0 of 2 completed
No. Input security and authorization are application responsibilities.
Only if it supports a defined review policy; source evidence and deterministic checks are often more useful.
Explore 500+ free tutorials across 20+ languages and frameworks.