mozilla/pdf.js · error · Error
No valid response from the AI service.
Error message
No valid response from the AI service.
What it means
Thrown by StampEditor.mlGuessAltText when the guess response is present, error-free, and not cancelled, but lacks an `output` string. It guards the final step that uses response.output as the alt text, so an empty/malformed success response is rejected rather than silently producing empty alt text.
Source
Thrown at src/display/editor/stamp.js:192
name: "altText",
request: {
data,
width,
height,
channels: data.length / (width * height),
},
});
if (!response) {
throw new Error("No response from the AI service.");
}
if (response.error) {
throw new Error("Error from the AI service.");
}
if (response.cancel) {
return null;
}
if (!response.output) {
throw new Error("No valid response from the AI service.");
}
const altText = response.output;
await this.setGuessedAltText(altText);
if (updateAltTextData && !this.hasAltTextData()) {
this.altTextData = { alt: altText, decorative: false };
}
return altText;
}
#getBitmap() {
if (this.#bitmapId) {
this._uiManager.enableWaiting(true);
this._uiManager.imageManager
.getFromId(this.#bitmapId)
.then(data => this.#getBitmapFetched(data, /* fromId = */ true))
.finally(() => this.#getBitmapDone());
return;
}View on GitHub (pinned to 5903d58d58)
Solutions
- Verify the ML backend returns { output: <non-empty string> } on success.
- Ensure the alt-text model is the version expecting the {data,width,height,channels} request shape.
- Catch the error and degrade to manual alt-text entry.
- Log the full response object upstream of the throw to confirm the missing key.
Example fix
// before
const alt = await editor.mlGuessAltText();
// after
try {
const alt = await editor.mlGuessAltText();
} catch (e) {
console.warn('Alt-text guess returned no usable output');
} Defensive patterns
Strategy: try-catch
Validate before calling
// Cannot fully validate server output client-side; at least confirm the backend contract.
// Ensure your mlManager normalizes responses to { output: string } on success. Type guard
function isValidAltTextResponse(r) {
return !!r && !r.error && !r.cancel && typeof r.output === 'string' && r.output.length > 0;
} Try / catch
try {
const alt = await editor.mlGuessAltText();
} catch (e) {
if (e.message === 'No valid response from the AI service.') {
// schema mismatch; fall back to manual entry
}
} Prevention
- Pin the alt-text model version and its response schema.
- Have your mlManager wrap/normalize responses to always include a non-empty output string.
- Log the raw response upstream of the throw to catch schema drift early.
- Never block editing on a successful ML guess; keep manual entry available.
When it happens
Trigger: mlManager.guess resolves to an object with no error, no cancel, and a falsy `output` (e.g. { output: '' } or { } ).
Common situations: The model returned an empty string for an unrecognizable image; the backend schema changed and the text moved off the `output` key; a proxy trimmed the response body.
Related errors
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/5678be58c8c1314e.
Report an issue: GitHub.