class EmptyContentErrorLangChainError<this>Error thrown by non-streaming calls (.invoke(), .generate(),
.batch()) when a Gemini candidate is returned with no usable content.
This covers two distinct situations that both surface the same way ā
a candidate with no content at all:
blockReason).MAX_TOKENS)
or an invalid tool call (MALFORMED_FUNCTION_CALL) ā nothing was
"blocked" in either case, the model simply returned nothing.Previously this was silently converted into an empty message; it's now
surfaced as a typed, catchable error. Check finishReason/blockReason
to distinguish an explicit block from the model just being odd.
Note: .stream() does not throw this error. A contentless candidate
mid-stream is silently skipped there instead, since a single missing
chunk isn't necessarily fatal to an otherwise-successful stream.
Optional custom error message. If not provided, a default message is
generated from finishReason/blockReason.
try {
await model.invoke("...");
} catch (error) {
if (EmptyContentError.isInstance(error)) {
console.log(`No content: ${error.finishReason ?? error.blockReason}`);
}
}