FlowiseAI/Flowise · error · Error

Invalid JSON in StructuredOutputParser: ${exception}

Error message

Invalid JSON in StructuredOutputParser: ${exception}

What it means

StructuredOutputParser.init wraps its parser construction in try/catch and rethrows any failure as 'Invalid JSON in StructuredOutputParser'. The catch is broad — it captures failures from JSON.parse on the schema string, jsonrepair attempts, and defineProperty operations on the structured output parser instance.

Source

Thrown at packages/components/nodes/outputparsers/StructuredOutputParser/StructuredOutputParser.ts:95

            const baseParse = structuredOutputParser.parse

            // Fix broken JSON from LLM
            structuredOutputParser.parse = (text) => {
                const jsonString = text.includes('```') ? text.trim().split(/```(?:json)?/)[1] : text.trim()
                return baseParse.call(structuredOutputParser, jsonrepair(jsonString))
            }

            // NOTE: When we change Flowise to return a json response, the following has to be changed to: JsonStructuredOutputParser
            Object.defineProperty(structuredOutputParser, 'autoFix', {
                enumerable: true,
                configurable: true,
                writable: true,
                value: autoFix
            })
            return structuredOutputParser
        } catch (exception) {
            throw new Error('Invalid JSON in StructuredOutputParser: ' + exception)
        }
    }
}

module.exports = { nodeClass: StructuredOutputParser }

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Validate the schema JSON with a JSON linter before pasting.
  2. Inspect `exception.message` for the parse offset and fix the cited location.
  3. If jsonrepair is failing, simplify the schema to find the unparseable fragment.
  4. Ensure the schema string is a plain JSON object, not a JS object literal.

Example fix

// before
} catch (exception) {
  throw new Error('Invalid JSON in StructuredOutputParser: ' + exception)
}
// after
} catch (exception) {
  const msg = exception instanceof Error ? exception.message : String(exception)
  throw new Error(`Invalid JSON in StructuredOutputParser: ${msg}. Input was: ${jsonString?.slice(0, 200)}`)
}
Defensive patterns

Strategy: validation

Validate before calling

function safeParseSchema(s: string): unknown {
  try { return JSON.parse(s) }
  catch {
    try { return JSON.parse(jsonrepair(s)) }
    catch (e) { throw new Error(`Schema JSON unparseable: ${(e as Error).message}`) }
  }
}

Type guard

const isJsonString = (s: string): boolean => { try { JSON.parse(s); return true } catch { return false } }

Try / catch

try { /* build parser */ }
catch (e) { throw new Error(`StructuredOutputParser failed: ${(e as Error).message}. Input: ${jsonString.slice(0,200)}`) }

Prevention

When it happens

Trigger: The schema JSON input is malformed (unbalanced braces, single quotes, trailing commas); the jsonrepair library cannot recover the string; defineProperty fails on a frozen/sealed parser instance.

Common situations: Hand-editing the JSON schema field; passing a schema string that includes comments or JS object syntax; version mismatch where the structured output parser shape changed.

Understand the failure class

Related errors


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