linshenkx/prompt-optimizer · error · EvaluationValidationError
${label} promptRef.kind must not be empty.
Error message
${label} promptRef.kind must not be empty. What it means
EvaluationValidationError thrown when snapshot.promptRef.kind is falsy. promptRef records what kind of prompt produced the run (e.g. a specific prompt/template reference) and its kind discriminator is mandatory. A missing kind makes the reference unresolvable, so validation fails.
Source
Thrown at packages/core/src/services/evaluation/service.ts:1736
private validateSnapshot(snapshot: EvaluationSnapshot | undefined, label: string): void {
if (!snapshot?.id?.trim()) {
throw new EvaluationValidationError(`${label} id must not be empty.`);
}
if (!snapshot?.label?.trim()) {
throw new EvaluationValidationError(`${label} label must not be empty.`);
}
if (!snapshot?.testCaseId?.trim()) {
throw new EvaluationValidationError(`${label} testCaseId must not be empty.`);
}
if (!snapshot?.promptText?.trim()) {
throw new EvaluationValidationError(`${label} promptText must not be empty.`);
}
if (!snapshot?.output?.trim()) {
throw new EvaluationValidationError(`${label} output must not be empty.`);
}
if (!snapshot?.promptRef?.kind) {
throw new EvaluationValidationError(`${label} promptRef.kind must not be empty.`);
}
if (snapshot.executionInput) {
this.validateContentBlock(snapshot.executionInput, `${label} executionInput`);
}
if (snapshot.outputBlock) {
this.validateContentBlock(snapshot.outputBlock, `${label} outputBlock`);
}
}
private normalizeContentBlock(block?: EvaluationContentBlock): NormalizedContentBlock | undefined {
const label = block?.label?.trim() || '';
const content = block?.content?.trim() || '';
if (!label || (!content && !this.hasBlockMedia(block))) {
return undefined;
}
const summary = block?.summary?.trim() || '';
return {View on GitHub (pinned to 3e677b1d9f)
Solutions
- Set snapshot.promptRef = { kind: <valid kind>, ... } matching the supported prompt reference kinds
- Check the PromptRef type/union in the package for the accepted kind values
- Upgrade callers to the schema version that requires promptRef and regenerate types
Example fix
// before
const snap = { ...base, promptRef: { id: prompt.id } };
// after
const snap = { ...base, promptRef: { kind: 'prompt', id: prompt.id } }; Defensive patterns
Strategy: validation
Validate before calling
const PROMPT_REF_KINDS = ['prompt','template'] as const; // check package's PromptRef type for real values
if (!PROMPT_REF_KINDS.includes(snapshot.promptRef?.kind)) throw new Error('promptRef.kind missing/invalid'); Type guard
function isPromptRef(v: unknown): v is { kind: string } { return typeof (v as any)?.kind === 'string' && (v as any).kind !== ''; } Prevention
- Always construct promptRef through a helper that sets kind from the PromptRef union
- Keep TS types strict so missing kind fails at compile time
When it happens
Trigger: Providing a snapshot with promptRef omitted entirely, set to null, or an object without a kind property (or kind: '').
Common situations: Optional promptRef added in a newer version of the schema but old callers don't send it; constructing promptRef: { id } while forgetting kind; deserialization dropping discriminated-union fields.
Related errors
- Unknown evaluation type: ${(request as any).type}
- Result evaluation snapshot testCaseId must match testCase.id
- Image result evaluation requires at least one output image e
- Compare evaluation requires at least one test case.
- Compare evaluation requires at least two snapshots.
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/43cb5b019e59a0f4.
Report an issue: GitHub.