🔨

错误处理演示

暂无描述

⬡ 8 节点 ↓ 12 下载 ⚙ workflow ⭐ 90/100 2026-05-28

工作流图谱

YAML 源码

app:
  description: ''
  icon: 🔨
  icon_background: '#FFEAD5'
  mode: workflow
  name: 错误处理演示
  use_icon_as_answer_icon: false
dependencies: []
kind: app
version: 0.1.5
workflow:
  conversation_variables: []
  environment_variables: []
  features:
    file_upload:
      allowed_file_extensions:
      - .JPG
      - .JPEG
      - .PNG
      - .GIF
      - .WEBP
      - .SVG
      allowed_file_types:
      - image
      allowed_file_upload_methods:
      - local_file
      - remote_url
      enabled: false
      fileUploadConfig:
        audio_file_size_limit: 50
        batch_count_limit: 5
        file_size_limit: 15
        image_file_size_limit: 10
        video_file_size_limit: 100
        workflow_file_upload_limit: 10
      image:
        enabled: false
        number_limits: 3
        transfer_methods:
        - local_file
        - remote_url
      number_limits: 3
    opening_statement: ''
    retriever_resource:
      enabled: true
    sensitive_word_avoidance:
      enabled: false
    speech_to_text:
      enabled: false
    suggested_questions: []
    suggested_questions_after_answer:
      enabled: false
    text_to_speech:
      enabled: false
      language: ''
      voice: ''
  graph:
    edges:
    - data:
        isInIteration: false
        sourceType: start
        targetType: llm
      id: 1732007415808-source-1733478262179-target
      source: '1732007415808'
      sourceHandle: source
      target: '1733478262179'
      targetHandle: target
      type: custom
      zIndex: 0
    - data:
        isInIteration: false
        sourceType: llm
        targetType: code
      id: 1733478262179-source-1733478343153-target
      source: '1733478262179'
      sourceHandle: source
      target: '1733478343153'
      targetHandle: target
      type: custom
      zIndex: 0
    - data:
        isInIteration: false
        sourceType: variable-aggregator
        targetType: end
      id: 1733478785564-source-1733478413552-target
      source: '1733478785564'
      sourceHandle: source
      target: '1733478413552'
      targetHandle: target
      type: custom
      zIndex: 0
    - data:
        isInIteration: false
        sourceType: llm
        targetType: code
      id: 1733479010027-source-17334785192390-target
      source: '1733479010027'
      sourceHandle: source
      target: '17334785192390'
      targetHandle: target
      type: custom
      zIndex: 0
    - data:
        isInIteration: false
        sourceType: code
        targetType: variable-aggregator
      id: 1733478343153-source-1733478785564-target
      source: '1733478343153'
      sourceHandle: source
      target: '1733478785564'
      targetHandle: target
      type: custom
      zIndex: 0
    - data:
        isInIteration: false
        sourceType: code
        targetType: llm
      id: 1733478343153-fail-branch-1733479010027-target
      source: '1733478343153'
      sourceHandle: fail-branch
      target: '1733479010027'
      targetHandle: target
      type: custom
      zIndex: 0
    - data:
        isInIteration: false
        sourceType: code
        targetType: variable-aggregator
      id: 17334785192390-source-1733478785564-target
      selected: false
      source: '17334785192390'
      sourceHandle: source
      target: '1733478785564'
      targetHandle: target
      type: custom
      zIndex: 0
    nodes:
    - data:
        desc: ''
        selected: false
        title: 开始
        type: start
        variables:
        - label: llm_string
          max_length: 10000
          options: []
          required: true
          type: paragraph
          variable: llm_string
      height: 90
      id: '1732007415808'
      position:
        x: 28.586897189782576
        y: 258.434485948913
      positionAbsolute:
        x: 28.586897189782576
        y: 258.434485948913
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        context:
          enabled: false
          variable_selector: []
        desc: ''
        model:
          completion_params:
            temperature: 0.7
          mode: chat
          name: claude-3-5-sonnet-20241022
          provider: langgenius/anthropic/anthropic
        prompt_template:
        - id: 362ad4bd-b8b9-4921-b81f-fc285eb76915
          role: system
          text: You are a teaching assistant. According to the user's request, only
            output an example code in incorrect JSON format.
        - id: 5f643c70-0cbe-4ad0-b0c5-c48ddcc6630b
          role: user
          text: This is the user's request:{{#1732007415808.llm_string#}}
        selected: false
        title: 生成错误的JSON
        type: llm
        variables: []
        vision:
          enabled: false
      height: 96
      id: '1733478262179'
      position:
        x: 370.4627858653985
        y: 258.434485948913
      positionAbsolute:
        x: 370.4627858653985
        y: 258.434485948913
      selected: true
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        code: "def main(json_str: str) -> dict:\n    obj = json.loads(json_str)\n\
          \    return {'result': obj}"
        code_language: python3
        desc: ''
        error_strategy: fail-branch
        outputs:
          result:
            children: null
            type: object
        selected: false
        title: 模拟JSON转义
        type: code
        variables:
        - value_selector:
          - '1733478262179'
          - text
          variable: json_str
      height: 90
      id: '1733478343153'
      position:
        x: 703.0873018641282
        y: 258.434485948913
      positionAbsolute:
        x: 703.0873018641282
        y: 258.434485948913
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        desc: ''
        outputs:
        - value_selector:
          - '1733478262179'
          - text
          variable: text1
        - value_selector:
          - '1733479010027'
          - text
          variable: text2
        - value_selector:
          - '1733478343153'
          - error_message
          variable: error_message
        - value_selector:
          - '1733478343153'
          - error_type
          variable: error_type
        - value_selector:
          - '1733478785564'
          - output
          variable: output
        selected: false
        title: 结束
        type: end
      height: 194
      id: '1733478413552'
      position:
        x: 2080.5186538686958
        y: 258.434485948913
      positionAbsolute:
        x: 2080.5186538686958
        y: 258.434485948913
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        code: "def main(json_str: str) -> dict:\n    obj = json.loads(json_str)\n\
          \    return {'result': obj}"
        code_language: python3
        desc: ''
        outputs:
          result:
            children: null
            type: object
        selected: false
        title: 二次执行
        type: code
        variables:
        - value_selector:
          - '1733479010027'
          - text
          variable: json_str
      height: 54
      id: '17334785192390'
      position:
        x: 1373.8226179034425
        y: 424.5052623051213
      positionAbsolute:
        x: 1373.8226179034425
        y: 424.5052623051213
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        desc: ''
        output_type: object
        selected: false
        title: 变量聚合器
        type: variable-aggregator
        variables:
        - - '1733478343153'
          - result
        - - '17334785192390'
          - result
      height: 130
      id: '1733478785564'
      position:
        x: 1707.276616168043
        y: 258.434485948913
      positionAbsolute:
        x: 1707.276616168043
        y: 258.434485948913
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        context:
          enabled: false
          variable_selector: []
        desc: ''
        model:
          completion_params:
            temperature: 0.7
          mode: chat
          name: claude-3-5-sonnet-20241022
          provider: langgenius/anthropic/anthropic
        prompt_template:
        - id: 4451cc50-f360-4d42-a925-9cfb98d3babc
          role: system
          text: You are a JSON repair expert.
        - id: 9e04c9bc-db50-4804-9562-7505b521eebc
          role: user
          text: Based on the {{#1733478343153.error_type#}} and {{#1733478343153.error_message#}}
            from the first version (x), your response should only contain the corrected
            JSON for repairing {{#1733478262179.text#}}
        selected: false
        title: JSON修复
        type: llm
        variables: []
        vision:
          enabled: false
      height: 96
      id: '1733479010027'
      position:
        x: 1021.5785962468701
        y: 424.5052623051213
      positionAbsolute:
        x: 1021.5785962468701
        y: 424.5052623051213
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        author: Yevanchen
        desc: ''
        height: 215
        selected: false
        showAuthor: true
        text: '{"root":{"children":[{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"该演示生成不正确的JSON格式以模拟某些LLM无法输出格式良好的JSON的情况。在失败分支中,使用错误类型和错误消息通过LLM进行修复。最后,使用变量聚合器将其合并到主分支中以供正常使用。这里使用变量聚合器是因为失败分支实际上是一个嵌入式if-else分支。当dify中的下游节点需要引用来自上游的多个可能条件分支的值时,必须使用变量聚合器统一聚合它们,然后才能引用。","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1,"textFormat":0}],"direction":"ltr","format":"","indent":0,"type":"root","version":1}}'
        theme: blue
        title: ''
        type: ''
        width: 503
    ...(过长已截断)