binary-husky/gpt_academic · error · RuntimeError

由于提问含不合规内容被过滤。

Error message

由于提问含不合规内容被过滤。

What it means

RuntimeError raised after the stream completes when the final chunk's finish_reason equals 'content_filter'. OpenAI/Azure moderation flagged the prompt or generated content as policy-violating and terminated the response early. The bridge inspects finish_reason on the last json_data once the delta loop ends, so this is a post-stream check, not a transport failure.

Source

Thrown at request_llms/bridge_chatgpt.py:219

        if (not has_content) and has_role: continue
        if (not has_content) and (not has_role): continue # raise RuntimeError("发现不标准的第三方接口:"+delta)
        if has_content: # has_role = True/False
            result += delta["content"]
            if not console_silence: print(delta["content"], end='')
            if observe_window is not None:
                # 观测窗,把已经获取的数据显示出去
                if len(observe_window) >= 1:
                    observe_window[0] += delta["content"]
                # 看门狗,如果超过期限没有喂狗,则终止
                if len(observe_window) >= 2:
                    if (time.time()-observe_window[1]) > watch_dog_patience:
                        raise RuntimeError("用户取消了程序。")
        else: raise RuntimeError("意外Json结构:"+delta)

    finish_reason = json_data.get('finish_reason', None) if json_data else None
    if finish_reason == 'content_filter':
        raise RuntimeError("由于提问含不合规内容被过滤。")
    if finish_reason == 'length':
        raise ConnectionAbortedError("正常结束,但显示Token不足,导致输出不完整,请削减单次输入的文本量。")

    return result


def predict(inputs:str, llm_kwargs:dict, plugin_kwargs:dict, chatbot:ChatBotWithCookies,
            history:list=[], system_prompt:str='', stream:bool=True, additional_fn:str=None):
    """
    发送至chatGPT,流式获取输出。
    用于基础的对话功能。
    inputs 是本次问询的输入
    top_p, temperature是chatGPT的内部调优参数
    history 是之前的对话列表(注意无论是inputs还是history,内容太长了都会触发token数量溢出的错误)
    chatbot 为WebUI中显示的对话列表,修改它,然后yield出去,可以直接修改对话界面内容
    additional_fn代表点击的哪个按钮,按钮见functional.py
    """
    from request_llms.bridge_all import model_info

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. Rephrase the question to remove policy-sensitive wording; split sensitive material into smaller neutral chunks.
  2. Start a new conversation — filter scores accumulate over history, and a fresh chat often passes.
  3. On Azure, request an adjusted content filter configuration for your subscription/deployment via the Azure OpenAI access form.
  4. If the input is legitimately sensitive (research), route through a model/endpoint without the same filter or summarize the material before sending.
Defensive patterns

Strategy: fallback

Try / catch

try:
    reply = predict_no_ui_long_connection(...)
except RuntimeError as e:
    if '不合规内容被过滤' in str(e):
        reply = retry_with_rephrased_prompt(neutralize(inputs))  # or reset history
    else:
        raise

Prevention

When it happens

Trigger: Prompts containing violence, sexual, self-harm, or other policy-flagged content (even in quoted/academic material); safety systems tripping on innocent medical/legal/security research text; Azure deployments with stricter default content filters; occasionally triggered by accumulated history rather than the latest message.

Common situations: Security-research or forensic prompts quoting malicious code; medical questions phrased clinically that the filter misreads; users on Azure OpenAI where content_filter aborts generation mid-answer; long chats where earlier messages slowly raise the risk score.

Related errors


AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14). Data as JSON: /api/errors/b31c20ec1947c66b. Report an issue: GitHub.