FlowiseAI/Flowise · error · Error

Invalid JSON in the FewShotPromptTemplate's examples: ${exce

Error message

Invalid JSON in the FewShotPromptTemplate's examples: ${exception}

What it means

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.

Source

Thrown at packages/components/nodes/prompts/FewShotPromptTemplate/FewShotPromptTemplate.ts:96

        ]
    }

    async init(nodeData: INodeData): Promise<any> {
        const examplesStr = nodeData.inputs?.examples
        const prefix = nodeData.inputs?.prefix as string
        const suffix = nodeData.inputs?.suffix as string
        const exampleSeparator = nodeData.inputs?.exampleSeparator as string
        const templateFormat = nodeData.inputs?.templateFormat as TemplateFormat
        const examplePrompt = nodeData.inputs?.examplePrompt as PromptTemplate

        const inputVariables = [...new Set([...getInputVariables(suffix), ...getInputVariables(prefix)])]

        let examples: Example[] = []
        if (examplesStr) {
            try {
                examples = typeof examplesStr === 'object' ? examplesStr : JSON.parse(examplesStr)
            } catch (exception) {
                throw new Error("Invalid JSON in the FewShotPromptTemplate's examples: " + exception)
            }
        }

        try {
            const obj: FewShotPromptTemplateInput = {
                examples,
                examplePrompt,
                prefix,
                suffix,
                inputVariables,
                exampleSeparator,
                templateFormat
            }
            const prompt = new FewShotPromptTemplate(obj)
            return prompt
        } catch (e) {
            throw new Error(e)
        }

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Provide examples as a JSON array of objects: `[{"input":"...","output":"..."}]`.
  2. Escape internal quotes and newlines (use `\n`, `\"`).
  3. Pass examples as an actual object/array from a prior node to skip parsing.
  4. Validate with a JSON linter before pasting.

Example fix

// before
examples = typeof examplesStr === 'object' ? examplesStr : JSON.parse(examplesStr)
// after
if (typeof examplesStr === 'string') {
  try { examples = JSON.parse(examplesStr) }
  catch (e) { throw new Error(`FewShot examples JSON parse failed: ${(e as Error).message}`) }
} else examples = examplesStr
Defensive patterns

Strategy: validation

Validate before calling

function parseExamples(input: unknown): Example[] {
  if (Array.isArray(input)) return input
  if (typeof input === 'string') {
    try { return JSON.parse(input) }
    catch (e) { throw new Error(`examples invalid JSON: ${(e as Error).message}`) }
  }
  return []
}

Type guard

const isExampleArray = (v: unknown): v is Example[] => Array.isArray(v) && v.every((x) => x && typeof x === 'object')

Prevention

When it happens

Trigger: Examples field holds invalid JSON; examples contain unescaped quotes/newlines; user pasted a YAML or JS-array literal instead of JSON.

Common situations: Authoring few-shot examples manually; pasting from documentation that uses non-JSON syntax; large examples with embedded quotes that break parsing.

Understand the failure class

Related errors


AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12). Data as JSON: /api/errors/be9fd702145c04be. Report an issue: GitHub.