You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LangChain LCEL链构建报错:不支持dict与NoneType的|运算

问题分析与解决

错误的核心原因是build_collection_vector_find_prompt_v2()函数没有返回有效的PromptTemplate实例:

  • 函数内部仅拼接了prompt字符串,但未将其包装为PromptTemplate对象并返回,导致该函数实际返回None
  • LCEL链式调用中,dict | None的操作不被支持,因此触发TypeError

修复方法

修改build_collection_vector_find_prompt_v2()函数,在末尾创建并返回PromptTemplate实例:

def build_collection_vector_find_prompt_v2() -> PromptTemplate:
    prompt = (
        get_helpful_assistant_prefix()
        + """ Based on the provided summary

        Generate a JSON object containing one or more of the following keys: seg_1, 
        seg_2, seg_3, seg_4, seg_5, . . . 

        Return ONLY this list of JSON objects."""
        + """
        PATH SEGMENT VALUES:

        {PathSegmentValues}

        USER INFORMATION SUMMARY:

        {UserInformationSummary}
        """
    )
    # 将拼接好的字符串转为PromptTemplate实例并返回
    return PromptTemplate.from_template(prompt)

这样函数会返回正确的PromptTemplate对象,LCEL的链式调用dict | PromptTemplate | ...就能正常执行。

内容的提问来源于stack exchange,提问作者devinbost

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 04:25:56