Study guides / CCDV-F / Domain 1

Applications & Integration · Lesson 3 of 11

1.3 - Vision: Working with Images

Send image content correctly and know what vision output still needs a human or a second check.

Images enter a message as a content block of type image, alongside or instead of text blocks, with a source that is either base64-encoded bytes plus a media_type (image/jpeg, image/png, image/gif, or image/webp), or a hosted URL Claude fetches itself. Multiple images can sit in one turn, in any order relative to text blocks — useful for comparing two screenshots, reading a multi-page scanned document a page at a time, or asking Claude to spot the difference between a before and an after. There's a per-request limit on how many images you can include and a maximum image size; oversized images get downscaled automatically before the model sees them, which is worth knowing when a very large source image doesn't behave the way a smaller crop of the same region would.

Images cost tokens too

An image is not free context — it's converted into a token count that scales with its resolution, and that count is added to input_tokens the same as any text would be. A large, unnecessarily high-resolution screenshot when a modest crop would do is a real, avoidable cost, and it's also more tokens the model has to attend across, which can dilute focus on the part of the image that actually matters. Downscaling or cropping to the relevant region before sending is a legitimate and often-tested optimisation, not just a nice-to-have.

Where vision needs a second check

Vision is strong at description, layout understanding, chart-trend summarisation, and reading clean, well-lit text, but exact numeric or fine-grained extraction (a total on a receipt, a small value on a dense chart, a serial number in a low-resolution photo) is exactly where a model can misread a digit — a 3 for an 8, a comma for a decimal point. Application design for a vision feature that feeds a downstream decision should verify an extracted value against the source — either with a second pass, a checksum-style rule, a comparison against a second independent signal, or a human glance — rather than trusting the first read outright. This is not unique to Claude; it's a property of vision-based extraction generally, and the exam treats it as a design-pattern question, not a model-capability trivia question.

Key concept

Treat vision output the same way you'd treat OCR output: probably right, cheap to get, worth a validation step before it drives an automated decision. The higher the stakes of what happens next (a payment, a compliance filing, a medical record), the more that validation step matters.

Vision plus tool use plus structured output

The strongest pattern for extracting a structured value from an image is combining vision input with a forced tool call: give Claude an image block and a tool whose input_schema defines exactly the fields you need (a numeric total, a string currency, maybe a confidence field you ask the model to self-report), and set tool_choice to force that tool. This turns a free-text description into a typed, directly-validatable object your code can check without any additional parsing step — and asking for an extra field like the currency symbol the model actually saw gives you a free cross-check for free: if the symbol doesn't match your assumed currency, that's a signal to flag the extraction rather than act on it.

Documents, not just images

A separate document content block type exists for PDFs, distinct from the image block — the API can process a PDF's pages directly (each page effectively contributes vision-style tokens, plus any extractable text layer), which means a multi-page scanned contract or report doesn't need to be pre-converted into individual page images by your own code before it reaches Claude. Mixing a document block with ordinary text and image blocks in the same message is allowed, so a single turn can reasonably ask Claude to compare a photographed whiteboard against a page of an uploaded PDF spec.

What vision reads reliably, and what it doesn't

Beyond the numeric-extraction caveat above, vision performance also degrades with image quality in predictable ways: heavy JPEG compression artifacts, low resolution relative to the text size, poor lighting or skewed photo angles on a document, and handwriting (which is read far less reliably than printed text) all increase the error rate. A chart with a legend and clearly labeled axes is read far more reliably than one where the relevant value has to be visually estimated against gridlines. None of this means vision is unreliable in general — for layout understanding, general description, and reading clean printed text it's strong — but it does mean the exam's emphasis on a verification step for high-stakes numeric extraction is describing a real, specific failure mode rather than a generic disclaimer.

Key concept

If your application controls how the source image is captured (a scanning flow you built, rather than an arbitrary user upload), investing in image quality at capture time — good lighting, a straight-on angle, adequate resolution — often reduces extraction errors more cost-effectively than adding a second model pass after the fact.

Exam traps

Practice question

An application extracts a dollar total from a photographed receipt using vision, then automatically issues a reimbursement for that amount with no human step. What's the main risk in this design?

  • A Vision requests are billed differently from text requests, so costs will be unpredictable.

    Cost predictability isn't the core risk here - a wrong reimbursement amount is.

  • B A misread digit on the receipt flows straight through to an incorrect payment with nothing to catch it. Correct

    Fine-grained numeric extraction is exactly where vision can err, and this design has no verification step before money moves.

  • C The Messages API doesn't support image input in the same request as a tool call.

    Image blocks and tool use can coexist in the same request; that's not a real constraint.

  • D Extended thinking must be enabled for any vision request to work at all.

    Vision works independently of extended thinking; it's not a prerequisite.

Build exercise: Extract a structured value from an image and add a sanity check

Intermediate · 30 minutes

You'll practice:

  1. Base64-encode a sample image (a screenshot of a simple invoice or receipt works well) and send it as an image content block alongside a short text instruction.

    Getting the block shape and media_type right is the first place vision requests actually fail.

    You should see: A successful response describing or answering a question about the image content.

    Hints
    1. What two things does an image source object need besides the base64 data itself?
    2. The source object needs type: "base64", a media_type matching the actual file format (e.g. image/png), and the base64-encoded data string.
    3. {"role":"user","content":[
        {"type":"image","source":{"type":"base64","media_type":"image/png","data":base64String}},
        {"type":"text","text":"What is the total shown on this receipt?"}
      ]}
  2. Define a tool with a numeric total field, a string currency field, and force Claude to call it with tool_choice, instead of accepting a free-text answer.

    Structured output via a tool schema, rather than free text, makes the extracted value easy to validate in code and gives you the currency symbol as a free cross-check.

    You should see: A tool_use block whose input contains a numeric total field and a currency field.

    Hints
    1. Why would asking for the currency symbol in the same tool call give you a free validation signal?
    2. If the currency Claude reports doesn't match what your system expects for this receipt's origin, that mismatch alone is worth flagging before trusting the total.
    3. tool_choice: { type: "tool", name: "record_receipt_total" }
      // input_schema requires: { total: number, currency: string }
  3. Add a sanity rule in your own code - reject totals above a threshold, or a currency mismatch, for manual review - rather than acting on the extracted value directly.

    This is the verification step a real application needs before an extracted value drives a decision.

    You should see: Values within threshold and matching currency pass through; anything above the threshold or with a mismatched currency gets flagged instead of auto-approved.

    Hints
    1. What's a reasonable, cheap-to-implement rule that catches a wildly wrong total without needing a second vision pass?
    2. A simple upper-bound threshold plus a currency-symbol check catches most of the failure modes at near-zero extra cost.
    3. if (extracted.total > 500 || extracted.currency !== expectedCurrency) {
        flagForManualReview(extracted);
      } else {
        autoApprove(extracted);
      }
  4. Re-run the same extraction on a deliberately cropped, lower-resolution version of the same receipt and compare the token usage reported in each response's usage.input_tokens.

    This makes the resolution-to-token-cost relationship concrete instead of an abstract rule to remember.

    You should see: The cropped, smaller image reports fewer input tokens than the full-resolution original for a functionally identical extraction.

    Hints
    1. If image tokens scale with resolution, what would you expect a smaller image to cost relative to a larger one covering the same information?
    2. A tighter crop at lower resolution should use meaningfully fewer input tokens while still giving the model enough detail to read the total correctly.
    3. console.log("full-res input_tokens:", fullResResponse.usage.input_tokens);
      console.log("cropped input_tokens:", croppedResponse.usage.input_tokens);

Sources