mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 09:36:44 +00:00
chore: Add telemetry on structured output errors (no-changelog) (#16389)
This commit is contained in:
@@ -31,6 +31,7 @@ export class N8nStructuredOutputParser extends StructuredOutputParser<
|
||||
const { index } = this.context.addInputData(NodeConnectionTypes.AiOutputParser, [
|
||||
[{ json: { action: 'parse', text } }],
|
||||
]);
|
||||
|
||||
try {
|
||||
const jsonString = text.includes('```') ? text.split(/```(?:json)?/)[1] : text;
|
||||
const json = JSON.parse(jsonString.trim());
|
||||
@@ -61,6 +62,24 @@ export class N8nStructuredOutputParser extends StructuredOutputParser<
|
||||
},
|
||||
);
|
||||
|
||||
// Add additional context to the error
|
||||
if (e instanceof SyntaxError) {
|
||||
nodeError.context.outputParserFailReason = 'Invalid JSON in model output';
|
||||
} else if (
|
||||
text.trim() === '{}' ||
|
||||
(e instanceof z.ZodError &&
|
||||
e.issues?.[0] &&
|
||||
e.issues?.[0].code === 'invalid_type' &&
|
||||
e.issues?.[0].path?.[0] === 'output' &&
|
||||
e.issues?.[0].expected === 'object' &&
|
||||
e.issues?.[0].received === 'undefined')
|
||||
) {
|
||||
nodeError.context.outputParserFailReason = 'Model output wrapper is an empty object';
|
||||
} else if (e instanceof z.ZodError) {
|
||||
nodeError.context.outputParserFailReason =
|
||||
'Model output does not match the expected schema';
|
||||
}
|
||||
|
||||
logAiEvent(this.context, 'ai-output-parsed', {
|
||||
text,
|
||||
response: e.message ?? e,
|
||||
|
||||
Reference in New Issue
Block a user