FlowiseAI/Flowise · error · Error
Invalid JSON object. Error: ${error}
Error message
Invalid JSON object. Error: ${error} What it means
ConditionAgent.parseJsonMarkdown locates a JSON block inside the LLM's response (handling ```json fences and bare braces), slices it out, and calls JSON.parse. If parse fails on the extracted substring, it throws 'Invalid JSON object. Error: <SyntaxError>'. This means a JSON-looking region was found but is syntactically malformed.
Source
Thrown at packages/components/nodes/agentflow/ConditionAgent/ConditionAgent.ts:242
// Find end of JSON
if (startIndex !== -1) {
for (const e of ends) {
endIndex = jsonString.lastIndexOf(e, jsonString.length)
if (endIndex !== -1) {
if (jsonString[endIndex] === '}') {
endIndex += 1
}
break
}
}
}
if (startIndex !== -1 && endIndex !== -1 && startIndex < endIndex) {
const extractedContent = jsonString.slice(startIndex, endIndex).trim()
try {
return JSON.parse(extractedContent)
} catch (error) {
throw new Error(`Invalid JSON object. Error: ${error}`)
}
}
throw new Error('Could not find JSON block in the output.')
}
async run(nodeData: INodeData, question: string, options: ICommonObject): Promise<any> {
let llmIds: ICommonObject | undefined
let analyticHandlers = options.analyticHandlers as AnalyticHandler
try {
const abortController = options.abortController as AbortController
// Extract input parameters
const model = nodeData.inputs?.conditionAgentModel as string
const modelConfig = nodeData.inputs?.conditionAgentModelConfig as ICommonObject
if (!model) {
throw new Error('Model is required')View on GitHub (pinned to abe4a8601a)
Solutions
- Use a stronger model or one with native JSON/structured-output mode for the Condition Agent.
- Lower temperature and tighten the system prompt / few-shot examples.
- Increase max_tokens so the JSON object is not truncated.
- Pre-validate the LLM string with a tolerant JSON parser (jsonrepair) before parseJsonMarkdown, or sanitize common issues (trailing commas, single quotes).
Example fix
// before
const parsed = parseJsonMarkdown(responseContent) // throws on trailing comma
// after — sanitize then parse
import { jsonrepair } from 'jsonrepair'
const repaired = jsonrepair(extractedContent)
const parsed = JSON.parse(repaired) Defensive patterns
Strategy: validation
Validate before calling
import { jsonrepair } from 'jsonrepair'
function safeParseJsonMarkdown(extracted) {
let repaired
try { repaired = jsonrepair(extracted) }
catch { throw new Error('LLM output is not repairable JSON') }
return JSON.parse(repaired)
} Type guard
function looksLikeJsonObject(s) {
const t = (s ?? '').trim(); return t.startsWith('{') && t.endsWith('}') } Try / catch
try { parsed = parseJsonMarkdown(responseContent) }
catch (e) {
if (/Invalid JSON object/.test(e.message)) {
// retry with a stricter prompt or a stronger model
} else throw e
} Prevention
- Use models with native JSON/structured-output mode.
- Keep temperature low for structured-output calls.
- Sanitize/repair LLM JSON before strict parsing.
When it happens
Trigger: LLM returns a fenced block that looks like JSON but contains trailing commas, single quotes, unquoted keys, comments, or truncated content; model output with mixed prose inside the braces; partial token streaming that cut off mid-object.
Common situations: Weaker/smaller model not following JSON instructions; temperature too high producing valid-ish but invalid JSON; max_tokens cutting the response mid-object; prompt change that confuses the model's output format.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Could not find JSON block in the output.
- LLM response is missing the "output" key or it is not a stri
- Failed to parse a valid scenario from the LLM's response. Pl
- chatflowId must be a valid array
- Model is required
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/e95672a6133b6741.
Report an issue: GitHub.