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:
@@ -121,9 +121,30 @@ export async function serverRoutes(app: FastifyInstance): Promise<void> {
|
||||
});
|
||||
} catch (err) {
|
||||
if (err instanceof SpecValidationError) {
|
||||
// Log the actual Zod validation failure so we can see *which* field
|
||||
// the model got wrong. Without this we can only see "422" in the
|
||||
// logs and can't tell whether to fix the prompt, the schema, or
|
||||
// the model output cleanup. Prompt is truncated to keep PII risk
|
||||
// bounded.
|
||||
app.log.warn(
|
||||
{
|
||||
zod_message: err.message,
|
||||
prompt: parsed.data.prompt.slice(0, 200),
|
||||
model: choice.displayName,
|
||||
},
|
||||
'preview_spec_invalid',
|
||||
);
|
||||
return reply.code(422).send({ error: 'spec_invalid', detail: err.message });
|
||||
}
|
||||
if (err instanceof BannedPatternError) {
|
||||
app.log.warn(
|
||||
{
|
||||
reason: err.message,
|
||||
prompt: parsed.data.prompt.slice(0, 200),
|
||||
model: choice.displayName,
|
||||
},
|
||||
'preview_banned_pattern',
|
||||
);
|
||||
return reply.code(422).send({ error: 'banned_pattern', detail: err.message });
|
||||
}
|
||||
if (err instanceof SpecTimeoutError) {
|
||||
|
||||
Reference in New Issue
Block a user