intake: only a reply that finished is a reply the schema constrained
liteLLMExtractor rejected finish_reason "length" and accepted everything else, so a content_filter or tool_calls stop was parsed as if the strict json_schema had held. Reject any reason present and not "stop", naming it.
This commit is contained in:
@@ -185,9 +185,19 @@ export function liteLLMExtractor(opts: {
|
|||||||
});
|
});
|
||||||
if (!response.ok) throw new ExtractionError(`LiteLLM returned ${response.status}`);
|
if (!response.ok) throw new ExtractionError(`LiteLLM returned ${response.status}`);
|
||||||
const raw = (await response.json()) as { choices?: { message?: { content?: string }; finish_reason?: string }[] };
|
const raw = (await response.json()) as { choices?: { message?: { content?: string }; finish_reason?: string }[] };
|
||||||
// A truncated reply can still parse once the JSON is closed, which quietly
|
// Only `stop` means the strict schema was satisfied. A truncated reply can
|
||||||
// drops the tail of a long receipt. Losing lines silently is worse than failing.
|
// still parse once the JSON is closed, which quietly drops the tail of a
|
||||||
if (raw.choices?.[0]?.finish_reason === "length") throw new ExtractionError("The receipt was too long to read in one pass.");
|
// long receipt; a `content_filter` or `tool_calls` stop is a different reply
|
||||||
|
// shape entirely. Accepting anything but `stop` accepts a reply the schema
|
||||||
|
// never constrained — losing lines silently is worse than failing.
|
||||||
|
const finish = raw.choices?.[0]?.finish_reason;
|
||||||
|
if (finish && finish !== "stop") {
|
||||||
|
throw new ExtractionError(
|
||||||
|
finish === "length"
|
||||||
|
? "The receipt was too long to read in one pass."
|
||||||
|
: `The model stopped before it finished (${finish}).`
|
||||||
|
);
|
||||||
|
}
|
||||||
const content = raw.choices?.[0]?.message?.content;
|
const content = raw.choices?.[0]?.message?.content;
|
||||||
if (!content) throw new ExtractionError("LiteLLM returned no content");
|
if (!content) throw new ExtractionError("LiteLLM returned no content");
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user