feat(preview): log spec validation failures with raw output
All checks were successful
Deploy to Production / deploy (push) Successful in 1m25s
All checks were successful
Deploy to Production / deploy (push) Successful in 1m25s
422s from /preview hid the actual reason: zod_message tells which field was wrong and a 400-char preview of the model output reveals refusals or non-JSON returns. Both stay in the api log only — never surfaced to the client unchanged.
This commit is contained in:
@@ -268,7 +268,13 @@ async function generateWithAnthropic(
|
||||
.join('');
|
||||
const json = extractJson(text);
|
||||
const parsed = GeneratorSpec.safeParse(json);
|
||||
if (!parsed.success) throw new SpecValidationError(parsed.error.message);
|
||||
if (!parsed.success) {
|
||||
// Include a truncated raw preview so the caller (api log) can see whether
|
||||
// the model returned non-JSON / a refusal / a near-miss schema, instead
|
||||
// of just the opaque zod error.
|
||||
const preview = text.slice(0, 400).replace(/\s+/g, ' ');
|
||||
throw new SpecValidationError(`${parsed.error.message} :: raw="${preview}"`);
|
||||
}
|
||||
scanForInjection(parsed.data);
|
||||
return { spec: parsed.data, source: 'claude' };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user