fix(gateway): make moderation score optional — LLM omits it in media batches

result.score was required by zod; the LLM (gemini-3.5-flash-lite via 9router)
occasionally omits it for media batches, hard-failing the whole batch parse
('Zod validation failed: expected number, received undefined' at
results[0].score). Callers already null-coalesce (result.score ?? 0) and the
parser clampScore()s it, so requiring it only caused parse failures.
Adds regression tests: media-batch without score parses (score->0), and
score-present responses still parse with the value.
This commit is contained in:
asepharyana committed 2026-09-02 13:15:05 +07:00
1 parent 4c38d53972
commit e6aa9af283
2 files changed
+61 -1

No files matched your search

@@ -23,7 +23,10 @@ export const ResultItemSchema = z.object({
message_id: z.union([z.string(), z.number()]).transform(String),
status: z.enum(["clean", "warn", "flagged"]),
flags: z.array(z.string()).optional(),
score: z.number(),
// score is optional — the LLM occasionally omits it (especially media
// batches) and callers already null-coalesce (`result.score ?? 0`).
// Requiring it hard-fails the whole batch parse for one missing field.
score: z.number().optional(),
analysis: z.string().nullable().optional(),
categories: z.array(z.string()).optional(),
severity: SeveritySchema.optional(),