{"record":{"id":"bb1fffe69ffdadd3","repo":"windmill-labs/windmill","slug":"no-code-block-found","errorCode":null,"errorMessage":"No code block found","messagePattern":"No code block found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"frontend/src/lib/components/copilot/lib.ts","lineNumber":1539,"sourceCode":"\t\t// partial code block, keep going\n\t\tmatch = response.match(/```[a-zA-Z]+\\n([\\s\\S]*)/)\n\n\t\tif (!match) {\n\t\t\tcontinue\n\t\t}\n\n\t\tcode = match[1]\n\t\tif (!code.endsWith('`')) {\n\t\t\t// skip displaying if possible that part of three ticks (end of code block)s\n\t\t\tgeneratedCode.set(code)\n\t\t}\n\t}\n\n\t// make sure we display the latest and complete code\n\tgeneratedCode.set(code)\n\n\tif (code.length === 0) {\n\t\tthrow new Error('No code block found')\n\t}\n\n\treturn code\n}\n","sourceCodeStart":1521,"sourceCodeEnd":1544,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/lib/components/copilot/lib.ts#L1521-L1544","documentation":"After extracting fenced code blocks from an AI completion, the code generator asserts the extracted code string is non-empty and throws 'No code block found' otherwise. generatedCode is set first so the UI shows whatever (empty) extraction happened. It means the model reply contained no usable code block.","triggerScenarios":"The AI response contained no fenced code block or the extraction regex matched zero/empty content — e.g. the model answered with prose only, a refusal, or an empty completion; also when the streaming reply was truncated before any code fence closed.","commonSituations":"Model refused the request (policy/safety) and returned an explanation; prompt asked a question instead of requesting code; provider returned an error message rendered as text; max_tokens cut the response before the code block.","solutions":["Retry generation — transient/truncated replies often succeed on a second attempt.","Rephrase the prompt to explicitly request code only, and check the script/flow kind matches the requested language.","Increase max output tokens or use a stronger model if the reply is being cut off.","Inspect the shown chat message to see whether the model refused or errored, and address that cause.","Check provider/credential health — a proxy error page can come back as plain text with no code."],"exampleFix":"// before\nconst code = await generateCode(prompt) // throws when model returns prose\n// after\nlet code\ntry {\n  code = await generateCode(prompt)\n} catch (e) {\n  if (e.message === 'No code block found') {\n    code = await generateCode(prompt + '\\nRespond ONLY with a fenced code block.')\n  } else { throw e }\n}","handlingStrategy":"retry","validationCode":"function extractCodeBlock(reply: string): string | null {\n  const m = reply.match(/```[\\w]*\\n([\\s\\S]*?)```/)\n  return m && m[1].trim() ? m[1] : null\n}","typeGuard":"function hasCodeBlock(reply: string): boolean {\n  return /```[\\w]*\\n[\\s\\S]+?```/.test(reply)\n}","tryCatchPattern":"try {\n  code = await generateCode(prompt)\n} catch (e) {\n  if (e.message === 'No code block found') {\n    // inspect the raw reply for a refusal, then retry once with a stricter prompt\n    code = await generateCode(prompt + '\\nRespond ONLY with one fenced code block.')\n  } else throw e\n}","preventionTips":["End generation prompts with an instruction to output only a fenced code block.","Check the raw reply for refusals/errors before attempting extraction.","Raise max output tokens to avoid truncated (unclosed) code fences.","Retry once automatically on empty extraction."],"tags":["ai-generation","parsing","empty-response","copilot"],"backgroundTag":"no-code-block-in-ai-response","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}