linshenkx/prompt-optimizer · error · EvaluationValidationError
${label} #${index + 1} must provide either assetId or b64.
Error message
${label} #${index + 1} must provide either assetId or b64. What it means
Each media item in an evaluation must reference its image by exactly one mechanism: either a stored assetId or inline base64 (b64). This error fires during validation when an item provides neither — both fields are absent or whitespace — so the service has no image payload to use.
Source
Thrown at packages/core/src/services/evaluation/service.ts:1679
private hasMediaPayload(mediaItem: EvaluationMediaItem | null | undefined): boolean {
const assetId = mediaItem?.assetId?.trim() || '';
const b64 = mediaItem?.b64?.trim() || '';
return !!assetId || !!b64;
}
private validateMediaItems(mediaItems: EvaluationMediaItem[], label: string): void {
mediaItems.forEach((item, index) => {
const itemLabel = item?.label?.trim() || '';
const assetId = item?.assetId?.trim() || '';
const b64 = item?.b64?.trim() || '';
if (!itemLabel) {
throw new EvaluationValidationError(`${label} #${index + 1} label must not be empty.`);
}
if (!assetId && !b64) {
throw new EvaluationValidationError(
`${label} #${index + 1} must provide either assetId or b64.`
);
}
if (assetId && b64) {
throw new EvaluationValidationError(
`${label} #${index + 1} must not provide both assetId and b64.`
);
}
});
}
private validateContentBlock(
block: EvaluationContentBlock | undefined,
label: string
): void {
if (!block) {
throw new EvaluationValidationError(`${label} must not be empty.`);View on GitHub (pinned to 3e677b1d9f)
Solutions
- Add either a valid assetId (from image storage) or a base64 data string to the offending media item
- If the image is missing entirely, remove the media item rather than submitting an empty shell
- Validate media arrays client-side before calling the evaluation API
Example fix
// before
media: [{ label: 'prompt image' }]
// after
media: [{ label: 'prompt image', b64: base64String }] Defensive patterns
Strategy: validation
Validate before calling
function validateMediaSources(media: { assetId?: string; b64?: string }[]): void {
media.forEach((item, i) => {
const hasAsset = !!item?.assetId?.trim();
const hasB64 = !!item?.b64?.trim();
if (!hasAsset && !hasB64) throw new Error(`media[${i}] needs assetId or b64`);
if (hasAsset && hasB64) throw new Error(`media[${i}] must not set both assetId and b64`);
});
} Type guard
const hasImageSource = (m: { assetId?: string; b64?: string } | undefined): boolean =>
!!(m?.assetId?.trim() ^ m?.b64?.trim()); // exactly one set Try / catch
try {
await evaluationService.create(request);
} catch (err) {
if (err instanceof EvaluationValidationError && /either assetId or b64/.test(err.message)) {
fixMediaItemFromMessage(err.message); // attach assetId or b64 to the named item
} else throw err;
} Prevention
- Model media items with a discriminated union: { kind: 'asset', assetId } | { kind: 'inline', b64 }
- Never default both fields when constructing items
- Validate media arrays client-side before submission
When it happens
Trigger: A media item in a content block's media array with neither assetId nor b64 (both missing, empty, or whitespace). The message includes the block label and 1-based item index.
Common situations: Building media items from user input where both fields were left blank; a form or importer that drops the image field when upload fails; refactoring code from b64 to assetId and accidentally removing both.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- ${label} #${index + 1} label must not be empty.
- ${label} #${index + 1} must not provide both assetId and b64
- ${label} must not be empty.
- Result evaluation snapshot testCaseId must match testCase.id
- Image result evaluation requires at least one output image e
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/8d2dd53691eb840c.
Report an issue: GitHub.