{"record":{"id":"a7a1a5e9c59b00c2","repo":"abhigyanpatwari/GitNexus","slug":"content-filter-triggered-mid-stream-the-generated","errorCode":null,"errorMessage":"content filter triggered mid-stream. The generated content was blocked by content policy. Adjust your prompt and retry.","messagePattern":"content filter triggered mid-stream\\. The generated content was blocked by content policy\\. Adjust your prompt and retry\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/wiki/llm-client.ts","lineNumber":515,"sourceCode":"        // Detect content filter finish reason — skip delta from this chunk\n        if (choice?.finish_reason === 'content_filter') {\n          contentFilterTriggered = true;\n          continue;\n        }\n\n        const delta = choice?.delta?.content;\n        if (delta) {\n          content += delta;\n          onChunk(content.length);\n        }\n      } catch {\n        // Skip malformed SSE chunks\n      }\n    }\n  }\n\n  if (contentFilterTriggered) {\n    throw new Error(\n      'content filter triggered mid-stream. The generated content was blocked by content policy. Adjust your prompt and retry.',\n    );\n  }\n\n  if (!content) {\n    throw new Error('LLM returned empty streaming response');\n  }\n\n  return { content };\n}\n","sourceCodeStart":497,"sourceCodeEnd":526,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/aac7515d2a8c50a1f8f923c6fb77218b333560d6/gitnexus/src/core/wiki/llm-client.ts#L497-L526","documentation":"During SSE streaming, the client saw a content_filter flag in the stream before/at completion and discards the partial content, telling you the generated text was blocked by content policy mid-generation. This differs from the non-streaming Azure 400 case: the request was accepted and streaming started, then the provider's safety system cut it off.","triggerScenarios":"Streaming call (useStream) where the provider emits a content-filter finish reason or error frame partway through; model begins a doc page whose generated content (often security/exploit-adjacent code text) trips filters after several tokens.","commonSituations":"Wiki generation for repos with security-tooling, weapon, drug, or graphic naming; providers with strict streaming filters (Azure OpenAI, some gateways); intermittent — same repo can pass or fail depending on sampled content.","solutions":["Adjust the prompt/source content: rename or exclude the module whose page keeps triggering the filter","Loosen/adjust the provider's content-filter configuration (Azure: filter settings per deployment)","Switch to a different provider or model with different filtering","Retry — mid-stream filters are often borderline-score dependent"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await callLLM(prompt, config, undefined, { onChunk });\n} catch (err) {\n  if (err instanceof Error && err.message.includes('content filter triggered mid-stream')) {\n    // partial content already streamed via onChunk — persist it as a stub and continue\n    return { content: partialContent + '\\n\\n[Generation blocked by content filter]' };\n  }\n  throw err;\n}","preventionTips":["Capture partial streamed content via onChunk so a filter kill doesn't lose everything","Adjust provider filter thresholds for repos with security-heavy vocabulary","Design wiki generation to skip-and-continue on per-module moderation failures"],"tags":["llm","content-filter","streaming","moderation","gitnexus"],"backgroundTag":"content-filter-blocked","analyzedSha":"aac7515d2a8c50a1f8f923c6fb77218b333560d6","analyzedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}