{"record":{"id":"be9fd702145c04be","repo":"FlowiseAI/Flowise","slug":"invalid-json-in-the-fewshotprompttemplate-s-exampl","errorCode":null,"errorMessage":"Invalid JSON in the FewShotPromptTemplate's examples: ${exception}","messagePattern":"Invalid JSON in the FewShotPromptTemplate's examples: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/prompts/FewShotPromptTemplate/FewShotPromptTemplate.ts","lineNumber":96,"sourceCode":"        ]\n    }\n\n    async init(nodeData: INodeData): Promise<any> {\n        const examplesStr = nodeData.inputs?.examples\n        const prefix = nodeData.inputs?.prefix as string\n        const suffix = nodeData.inputs?.suffix as string\n        const exampleSeparator = nodeData.inputs?.exampleSeparator as string\n        const templateFormat = nodeData.inputs?.templateFormat as TemplateFormat\n        const examplePrompt = nodeData.inputs?.examplePrompt as PromptTemplate\n\n        const inputVariables = [...new Set([...getInputVariables(suffix), ...getInputVariables(prefix)])]\n\n        let examples: Example[] = []\n        if (examplesStr) {\n            try {\n                examples = typeof examplesStr === 'object' ? examplesStr : JSON.parse(examplesStr)\n            } catch (exception) {\n                throw new Error(\"Invalid JSON in the FewShotPromptTemplate's examples: \" + exception)\n            }\n        }\n\n        try {\n            const obj: FewShotPromptTemplateInput = {\n                examples,\n                examplePrompt,\n                prefix,\n                suffix,\n                inputVariables,\n                exampleSeparator,\n                templateFormat\n            }\n            const prompt = new FewShotPromptTemplate(obj)\n            return prompt\n        } catch (e) {\n            throw new Error(e)\n        }","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/prompts/FewShotPromptTemplate/FewShotPromptTemplate.ts#L78-L114","documentation":"FewShotPromptTemplate.init parses `nodeData.inputs?.examples` (the few-shot examples array) as JSON. If the user-provided string is malformed, JSON.parse throws and the catch rethrows with this message.","triggerScenarios":"Examples field holds invalid JSON; examples contain unescaped quotes/newlines; user pasted a YAML or JS-array literal instead of JSON.","commonSituations":"Authoring few-shot examples manually; pasting from documentation that uses non-JSON syntax; large examples with embedded quotes that break parsing.","solutions":["Provide examples as a JSON array of objects: `[{\"input\":\"...\",\"output\":\"...\"}]`.","Escape internal quotes and newlines (use `\\n`, `\\\"`).","Pass examples as an actual object/array from a prior node to skip parsing.","Validate with a JSON linter before pasting."],"exampleFix":"// before\nexamples = typeof examplesStr === 'object' ? examplesStr : JSON.parse(examplesStr)\n// after\nif (typeof examplesStr === 'string') {\n  try { examples = JSON.parse(examplesStr) }\n  catch (e) { throw new Error(`FewShot examples JSON parse failed: ${(e as Error).message}`) }\n} else examples = examplesStr","handlingStrategy":"validation","validationCode":"function parseExamples(input: unknown): Example[] {\n  if (Array.isArray(input)) return input\n  if (typeof input === 'string') {\n    try { return JSON.parse(input) }\n    catch (e) { throw new Error(`examples invalid JSON: ${(e as Error).message}`) }\n  }\n  return []\n}","typeGuard":"const isExampleArray = (v: unknown): v is Example[] => Array.isArray(v) && v.every((x) => x && typeof x === 'object')","tryCatchPattern":null,"preventionTips":["Escape internal quotes and newlines in examples.","Prefer passing arrays from upstream nodes.","Validate with a JSON linter."],"tags":["json","validation","prompt","few-shot"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}