calesthio/OpenMontage · error · ValueError
prompt references <<<image_{max(existing_numbers)}>>> but on
Error message
prompt references <<<image_{max(existing_numbers)}>>> but only {len(references)} image(s) were provided What it means
Raised by build_image_references()/prompt validation in tools/_kling/omni.py when the prompt already contains <<<image_N>>> placeholders and the largest N exceeds the number of image references supplied. The guard prevents sending a prompt that references an image the backend cannot resolve.
Source
Thrown at tools/_kling/omni.py:32
) -> tuple[str, list[dict[str, Any]]]:
"""Bind image_list entries to stable Image Omni placeholders."""
references = [
{
"index": index,
"placeholder": f"<<<image_{index}>>>",
"source": item.get("source") or item.get("image") or item.get("image_url"),
"source_type": item.get("source_type", "unknown"),
}
for index, item in enumerate(image_list, start=1)
]
if not references:
return prompt, []
existing_numbers = [int(value) for value in PLACEHOLDER_RE.findall(prompt)]
if existing_numbers:
if max(existing_numbers) > len(references):
raise ValueError(
f"prompt references <<<image_{max(existing_numbers)}>>> but only {len(references)} image(s) were provided"
)
if min(existing_numbers) < 1:
raise ValueError("Image Omni prompt placeholders must start at <<<image_1>>>")
return prompt, references
placeholders = " ".join(item["placeholder"] for item in references)
return f"{prompt}\nReferences: {placeholders}", references
View on GitHub (pinned to 95e1c3d0ab)
Solutions
- Add the missing reference image(s) so the count matches the highest placeholder
- Or renumber the placeholders down to match the actual image count
- Prefer omitting placeholders entirely — the function auto-appends a 'References:' line when no placeholders exist
Example fix
// before
prompt, refs = build_image_references('use <<<image_2>>> as the character', images=[img1])
// after
prompt, refs = build_image_references('use <<<image_2>>> as the character', images=[img1, img2]) Defensive patterns
Strategy: validation
Validate before calling
import re
PLACEHOLDER_RE = re.compile(r'<<<image_(\-?\d+)>>>')
def placeholders_match_refs(prompt: str, image_count: int) -> bool:
nums = [int(n) for n in PLACEHOLDER_RE.findall(prompt)]
return not nums or (max(nums) <= image_count and min(nums) >= 1) Try / catch
try:
prompt, refs = build_image_references(prompt, images)
except ValueError as e:
if 'but only' in str(e):
# add images or rewrite prompt without high-numbered placeholders
raise ValueError(f'reference/prompt mismatch: {len(images)} images vs placeholders in prompt') from e
raise Prevention
- Generate placeholders programmatically with enumerate(images, start=1) so counts can't drift
- Or omit placeholders entirely and let the function append the References line
- Re-validate prompts whenever the image list changes
When it happens
Trigger: Prompt text contains <<<image_3>>> but only 2 images are passed in image_list; images were removed from the list but the prompt was not updated; index-based prompt written by hand off-by-one.
Common situations: Iterating on prompts while adding/removing reference images; LLM generating the prompt with hardcoded placeholder numbers that drift from the actual image count.
Related errors
- Image Omni prompt placeholders must start at <<<image_1>>>
- model_name {model_name!r} is not supported for api_family=om
- element_list must be a list of element ids or objects
- each element_list item must include element_id
- element_id must be an integer-compatible value: {raw_id!r}
AI-assisted analysis of calesthio/OpenMontage@95e1c3d0ab (2026-08-15).
Data as JSON: /api/errors/20d78baf51a743f9.
Report an issue: GitHub.