pbakaus/impeccable · error
embed-prompt: prompt too long for a JPEG segment
Error message
embed-prompt: prompt too long for a JPEG segment
What it means
JPEG embedding uses a COM marker segment whose length field is 16-bit (max 0xffff bytes). If keyword + NUL + prompt exceeds the segment capacity, the CLI refuses and exits 1 rather than producing a corrupt JPEG.
Source
Thrown at crates/context/src/embed_prompt.rs:321
o.extend_from_slice(&body);
o.extend_from_slice(&text_chunk);
o.extend_from_slice(&png_chunk(b"IEND", &[]));
o
} else {
let mut o = buf[..iend].to_vec();
o.extend_from_slice(&text_chunk);
o.extend_from_slice(&buf[iend..]);
o
};
let _ = std::fs::write(&file_abs, out);
io.out(&format!("EMBEDDED: {} (png tEXt, {} chars)\n", file, plen));
0
} else if jpeg {
let mut seg = KEYWORD.to_vec();
seg.push(0);
seg.extend_from_slice(prompt.as_bytes());
if seg.len() + 2 > 0xffff {
io.err("embed-prompt: prompt too long for a JPEG segment\n");
return 1;
}
let mut com = vec![0xff, 0xfe];
com.extend_from_slice(&((seg.len() + 2) as u16).to_be_bytes());
com.extend_from_slice(&seg);
let mut out = buf[..2].to_vec();
out.extend_from_slice(&com);
out.extend_from_slice(&buf[2..]);
let _ = std::fs::write(&file_abs, out);
io.out(&format!("EMBEDDED: {} (jpeg COM, {} chars)\n", file, plen));
0
} else {
let mut m = Map::new();
m.insert("prompt".into(), Value::String(prompt));
m.insert("createdAt".into(), Value::String(iso_now()));
let _ = std::fs::write(&sidecar_abs, json_pretty(&Value::Object(m)));
io.out(&format!("EMBEDDED: {} (sidecar fallback for this format)\n", sidecar));
0View on GitHub (pinned to 2bc2879276)
Solutions
- Shorten the prompt text before embedding into a JPEG.
- Embed into PNG instead (PNG tEXt has no 64KB segment limit) if the long prompt is required.
- Store the full prompt in a sidecar file and embed only a short reference.
Example fix
// before impeccable embed-prompt --image photo.jpg --prompt "$(cat huge-transcript.txt)" // after head -c 60000 huge-transcript.txt > short.txt impeccable embed-prompt --image photo.jpg --prompt "$(cat short.txt)"
Defensive patterns
Strategy: validation
Validate before calling
const KEYWORD = 'prompt'; if (Buffer.byteLength(KEYWORD) + 1 + Buffer.byteLength(prompt) + 2 > 0xffff) { throw new Error('prompt too long for JPEG COM segment'); } Try / catch
try { embedPrompt(jpeg, prompt); } catch (e) { if (/too long/.test(e.message)) prompt = prompt.slice(0, 60000); } Prevention
- Keep embedded prompts under ~60KB for JPEG targets
- Use PNG when embedding long prompts
- Store oversized prompts in sidecar files
When it happens
Trigger: Running `embed-prompt --image photo.jpg --prompt <very long text>` where the prompt (plus 1-byte keyword and separator) makes the COM segment exceed 65535 bytes.
Common situations: Embedding entire system-prompt transcripts or very long generation configs into JPEGs; PNG has no such limit but JPEG does.
Understand the failure class
Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.
Related errors
- embed-prompt: no embedded prompt found
- Update failed: Aborted.
- concept-seed: --candidate-count must be an integer from 5 to
- Unknown ignore-rule flag: ${arg}
- Pass a rule id, e.g. ${IMPECCABLE_COMMAND} hooks ignore-rule
AI-assisted analysis of pbakaus/impeccable@2bc2879276 (2026-09-08).
Data as JSON: /api/errors/a2f8bfe3ab627d8b.
Report an issue: GitHub.