{"record":{"id":"ae8a8d549f473cc6","repo":"FlowiseAI/Flowise","slug":"could-not-find-json-block-in-the-output","errorCode":null,"errorMessage":"Could not find JSON block in the output.","messagePattern":"Could not find JSON block in the output\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/agentflow/ConditionAgent/ConditionAgent.ts","lineNumber":246,"sourceCode":"                if (endIndex !== -1) {\n                    if (jsonString[endIndex] === '}') {\n                        endIndex += 1\n                    }\n                    break\n                }\n            }\n        }\n\n        if (startIndex !== -1 && endIndex !== -1 && startIndex < endIndex) {\n            const extractedContent = jsonString.slice(startIndex, endIndex).trim()\n            try {\n                return JSON.parse(extractedContent)\n            } catch (error) {\n                throw new Error(`Invalid JSON object. Error: ${error}`)\n            }\n        }\n\n        throw new Error('Could not find JSON block in the output.')\n    }\n\n    async run(nodeData: INodeData, question: string, options: ICommonObject): Promise<any> {\n        let llmIds: ICommonObject | undefined\n        let analyticHandlers = options.analyticHandlers as AnalyticHandler\n\n        try {\n            const abortController = options.abortController as AbortController\n\n            // Extract input parameters\n            const model = nodeData.inputs?.conditionAgentModel as string\n            const modelConfig = nodeData.inputs?.conditionAgentModelConfig as ICommonObject\n            if (!model) {\n                throw new Error('Model is required')\n            }\n            const modelName = modelConfig?.model ?? modelConfig?.modelName\n\n            const conditionAgentInput = nodeData.inputs?.conditionAgentInput as string","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/agentflow/ConditionAgent/ConditionAgent.ts#L228-L264","documentation":"ConditionAgent.parseJsonMarkdown throws 'Could not find JSON block in the output.' when it cannot find any recognized start/end delimiters (```json, ```, backticks, or { } ) with a valid ordering in the LLM response. This means the model returned plain prose or a format the extractor does not recognize — no JSON region to even attempt parsing.","triggerScenarios":"LLM returns a pure natural-language answer with no JSON; model returns only the scenario name as text without braces/fences; empty response; response using a delimiter the parser doesn't look for (e.g. indented YAML, XML tags).","commonSituations":"Model ignores the structured-output instruction entirely; system prompt overridden in a way that drops the JSON requirement; very small model that can't follow formatting; context window dominated by history leaving no room for the instruction.","solutions":["Reinforce JSON output in the system prompt and keep the few-shot example intact.","Switch to a model that reliably follows formatting instructions.","Reduce injected chat history / input size so the instruction is not crowded out.","If overriding the system prompt, ensure it still mandates a fenced JSON object with an 'output' key."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function hasJsonRegion(s) {\n  return /\\{[\\s\\S]*\\}|```json/i.test(s ?? '')\n}\nif (!hasJsonRegion(responseContent)) {\n  // retry the LLM call with a stronger JSON instruction instead of throwing\n}","typeGuard":"function containsJsonBlock(s) {\n  return /```json|```|`|\\{/.test(s ?? '')\n}","tryCatchPattern":"try { parsed = parseJsonMarkdown(responseContent) }\ncatch (e) {\n  if (/Could not find JSON block/.test(e.message)) {\n    // re-prompt with explicit 'respond ONLY with fenced JSON'\n  } else throw e\n}","preventionTips":["Make the JSON requirement the last instruction in the prompt.","Always include the few-shot JSON example.","Avoid overriding the system prompt in ways that drop the format mandate."],"tags":["condition-agent","llm-output","structured-output","parsing"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}