Tutorials Logic, IN info@tutorialslogic.com

Claude Vision: Extract a Receipt Without Trusting the Upload

A visual input is evidence, not authority

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.

The working example: A customer uploads a receipt to support a billing request. Your application validates access and the file first; Claude extracts a draft; code or a reviewer verifies the result. Validate files before they reach the model and treat model-extracted values like user-submitted data until your application verifies them.

The receipt flow has three distinct checks

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

Choose a narrow visual task with a visible answer

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.

  • Use typed content arrays for multi-part requests.
  • Keep task instructions separate from source data.
  • Review current supported types and limits before shipping.

Protect the upload path before you add intelligence

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.

  • Verify ownership and tenancy.
  • Validate bytes, size, and type.
  • Apply data retention and privacy rules.

Ask for fields a workflow can inspect

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.

  • Request named fields and source references.
  • Allow uncertainty.
  • Reconcile critical values in code.

Design uncertainty as a normal result

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.

  • Escalate by impact.
  • Use deterministic validation where possible.
  • Retain review evidence for sensitive work.

Validate the upload before Claude sees it

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.

  • Verify ownership before reading the file.
  • Use a MIME allow-list and size limit.
  • Validate totals and IDs after extraction.

Build a receipt-review path

Validate an Upload Before Model Use

This example shows an application-level allow list. A production handler should also inspect file signatures, isolate storage, and enforce per-user authorization.

Validate an Upload Before Model Use
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))
Output
accepted
  • Model invocation starts only after this validation passes.

Validate an Extracted Total

Model output must satisfy the same validation as any other input before it is saved.

Validate an Extracted Total
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"))
Output
149.50
  • Invalid or negative values become review cases.

Reject an Unsupported Upload

The model is not a file-security scanner. Accept only file types your feature deliberately supports.

Reject an Unsupported Upload
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))
Output
True
  • Production upload checks should also inspect the file signature and tenant ownership.

Flag a Receipt That Needs Review

A deterministic check can catch an obvious mismatch after extraction.

Flag a Receipt That Needs Review
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]))
Output
False
  • Use a decimal money type in a real accounting workflow.
Before a file becomes model context

Visual-input safety check

4 checks
  • I validate files before model use.
  • I can separate extraction from verification.
  • I retain source context for important fields.
  • I have an uncertainty and review path.

Where receipt and document workflows usually go wrong

  • Trusting filename extensions as file validation.
  • Sending a whole private document when a redacted excerpt is sufficient.
  • Forcing the model to infer unreadable or missing fields.

Use a file your product already handles

Design one extraction workflow

0 of 2 completed

Questions about visual and document inputs

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.

Next Step
Next Practice

Finish the concept here, then reinforce it with hands-on coding, interview prep, or a tool that matches the topic.

Browse Free Tutorials

Explore 500+ free tutorials across 20+ languages and frameworks.