Combining Text and Images
Unified multimodal prompts.
Combining Text and Images is a free AI Prompt Engineering lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AI Prompt Engineering learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Unified Multimodal Prompt
A multimodal prompt is not text plus an attached image. It is a single interleaved sequence where image tokens and text tokens occupy the same context and attend to one another. The model does not 'look at the picture then read the text' — it processes a fused token stream.
- Image patches are projected into the same embedding space as text tokens.
- Ordering matters: a question placed before an image primes different attention than one placed after.
- You are authoring one prompt with two surface forms, not two prompts.
Interleaving Order and Anchoring
Where you place the image relative to the instruction changes behavior. Placing the instruction after the image lets the model condition the question on what it has already encoded; placing it before turns the image into evidence for a pre-stated task.
For multi-image prompts, label each image inline so later text can reference it unambiguously ([Image 1], [Image 2]).
messages = [
{'role': 'user', 'content': [
{'type': 'text', 'text': 'You will see two product photos.'},
{'type': 'text', 'text': 'Image 1:'},
{'type': 'image', 'source': img_a},
{'type': 'text', 'text': 'Image 2:'},
{'type': 'image', 'source': img_b},
{'type': 'text', 'text': 'Which has better lighting? Cite the image label.'}
]}
]Task Framing Before Encoding
Vision encoders are lossy: detail not relevant to the implicit task can be discarded during pooling. If you state the task before the image, you bias the model toward attending to the regions that matter.
- Generic caption requests yield generic features.
- A specific question ('count the resistors on the board') focuses representational budget on the relevant subregions.
Front-load specificity when fine detail is needed.
Resolution and Tiling Budgets
Most vision models tile high-resolution images into fixed-size patches, each costing tokens. A 2000x2000 image may be split into many tiles, each downsampled. Token budget is the silent constraint of multimodal prompting.
- Crop to the region of interest before sending — do not rely on the model to zoom.
- For dense documents, send page crops rather than a single full-page image.
- Know your provider's max tiles; beyond it, fine text becomes unreadable.
def estimate_image_tokens(w, h, tile=512, per_tile=256):
import math
tiles = math.ceil(w / tile) * math.ceil(h / tile)
return tiles * per_tile + per_tile # + thumbnailText as Structured Schema for Vision
Combine the image with an explicit output schema in the text channel. The image supplies content; the text supplies the contract. This is far more reliable than free-form description.
Ask for JSON keyed to entities you expect to see, and instruct the model to emit null for fields not visible — this suppresses hallucinated detail.
instruction = (
'Extract from the receipt image. Return JSON: '
'{"merchant": str|null, "total": number|null, '
'"date": str|null, "line_items": [{"name": str, "price": number}]}. '
'Use null when a field is not legible. Do not invent values.'
)Disambiguating With Deixis
Deictic references ('this', 'the one on the left', 'the highlighted box') bind text to image regions. When you can pre-annotate the image (draw a box, add an arrow) the text reference becomes far more robust than spatial language alone.
- Spatial words ('top-right') are error-prone under rotation or crop.
- An overlaid numbered marker plus 'object #3' is unambiguous.
- Pre-processing the image to add markers is a legitimate prompt-engineering move.
Few-Shot With Mixed Modalities
You can supply image-to-text exemplars to lock format and reasoning style. Each shot is an interleaved (image, ideal-answer) pair. The model induces the mapping from the demonstrations.
Keep exemplar images representative of the real distribution — an exemplar from a different domain teaches the wrong feature selection.
shots = [
('image', chart_a), ('text', 'Trend: upward. Peak: Q3. Anomaly: none.'),
('image', chart_b), ('text', 'Trend: flat. Peak: Q1. Anomaly: Q4 dip.'),
('image', target_chart), ('text', 'Trend:') # model completes
]Grounding Claims to Pixels
For high-stakes extraction, require the model to cite where in the image each claim originates. Approximate bounding boxes or quoted on-image text act as verifiable evidence and dramatically reduce confident fabrication.
- 'For each value, quote the exact label text you read.'
- 'Give an approximate normalized box [x0,y0,x1,y1] per field.'
Grounding turns an opaque answer into an auditable one.
Failure Modes to Guard Against
Multimodal models fail in characteristic ways:
- OCR drift on small or stylized fonts — digits like 1/7 and 0/O confuse.
- Counting collapse beyond ~6 similar objects.
- Caption bias: describing the typical scene rather than the actual one.
- Text-channel override: a confident wrong text claim can suppress correct visual evidence.
Mitigate by asking the model to derive from the image first, then reconcile with any text assertions.
Reconciliation Prompts
When text context and image conflict, you must decide precedence explicitly — the model has no default policy you can trust. State it: 'If the image contradicts the supplied metadata, trust the image and flag the discrepancy.'
This single sentence converts silent error into an explicit, surfaced conflict your downstream pipeline can route for review.
policy = (
'You are given metadata AND a photo. '
'When they disagree, prefer the photo as ground truth. '
'Emit {"value": ..., "conflict": bool, "note": str}.'
)Architecting a Fusion Pipeline
Production multimodal prompting is a pipeline, not a single call:
- Pre-process: crop, annotate, downscale to budget.
- Fuse: interleave with a task-first instruction and output schema.
- Ground: require per-claim evidence.
- Reconcile: state precedence between modalities.
- Validate: parse JSON, check nulls and conflict flags.
Each stage shrinks the failure surface that pure prompting cannot.
Quick Check
You must extract fine print from a high-resolution contract scan and need reliable numbers.
Recap: Fusing Text and Images
A unified multimodal prompt is one interleaved token stream. Key moves: task-first framing to steer the vision encoder, resolution/tiling awareness via cropping, explicit output schemas with nullable fields, pixel grounding for every claim, and stated modality precedence for conflicts. Treat it as a pipeline — pre-process, fuse, ground, reconcile, validate — and the brittle parts of vision prompting become controllable.
Frequently asked questions
Is the “Combining Text and Images” lesson free?
Yes — the full text of “Combining Text and Images” is free to read here on the web, and the AI Prompt Engineering course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AI Prompt Engineering course, upgrade to CoddyKit PRO.
What will I learn in “Combining Text and Images”?
Unified multimodal prompts. You practise AI Prompt Engineering with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AI Prompt Engineering?
No prior experience is required. AI Prompt Engineering on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Combining Text and Images” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AI Prompt Engineering lesson?
Yes. Every AI Prompt Engineering lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Combining Text and Images
- Grounding Across Modalities
- Audio, Text and Vision Together
- Multimodal Output Control