mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(Structured Output Parser Node): Handle passed objects that do not match schema (#17774)
This commit is contained in:
@@ -608,6 +608,33 @@ describe('OutputParserStructured', () => {
|
||||
),
|
||||
).rejects.toThrow('Required');
|
||||
});
|
||||
|
||||
it('should raise schema fit error when passing in empty object', async () => {
|
||||
const jsonExample = `{
|
||||
"user": {
|
||||
"name": "Alice",
|
||||
"email": "alice@example.com",
|
||||
"profile": {
|
||||
"age": 30,
|
||||
"city": "New York"
|
||||
}
|
||||
},
|
||||
"tags": ["work", "important"]
|
||||
}`;
|
||||
thisArg.getNodeParameter.calledWith('schemaType', 0).mockReturnValueOnce('fromJson');
|
||||
thisArg.getNodeParameter
|
||||
.calledWith('jsonSchemaExample', 0)
|
||||
.mockReturnValueOnce(jsonExample);
|
||||
|
||||
const { response } = (await outputParser.supplyData.call(thisArg, 0)) as {
|
||||
response: N8nStructuredOutputParser;
|
||||
};
|
||||
|
||||
// @ts-expect-error 2345
|
||||
await expect(response.parse({})).rejects.toThrow(
|
||||
"Model output doesn't fit required format",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('manual schema mode', () => {
|
||||
|
||||
@@ -66,7 +66,7 @@ export class N8nStructuredOutputParser extends StructuredOutputParser<
|
||||
if (e instanceof SyntaxError) {
|
||||
nodeError.context.outputParserFailReason = 'Invalid JSON in model output';
|
||||
} else if (
|
||||
text.trim() === '{}' ||
|
||||
(typeof text === 'string' && text.trim() === '{}') ||
|
||||
(e instanceof z.ZodError &&
|
||||
e.issues?.[0] &&
|
||||
e.issues?.[0].code === 'invalid_type' &&
|
||||
|
||||
Reference in New Issue
Block a user