Skip to content

Conversation

@CrabSAMA
Copy link
Contributor

@CrabSAMA CrabSAMA commented Jan 29, 2026

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Fixes #31118

This pr introduce new error handling of LLM node, which user can select fallback model list when model run throw exception.

Before: every LLM node need add exception branch or use tool to make model fallback.
LLM node run failed -> error branch -> some logic about handle fallback -> end

Now: it can config fallback model in LLM node which need fallback.
LLM node run failed -> traverse fallback model list -> retry with fallback model -> end

Some edge case:

  • If fallback model list is empty, it just like none error handling
  • If fallback model list traverse fully and also failed, it will make workflow failed

Changelog:

  1. backend add enum about ERROR_STRATEGY, add some metadata field to store fallback model info
  2. backend add unittest about this feature
  3. frontend add logic about parse fallback model info, and support display model attempt info

TODO:

  • communicate about this feature
  • add docs about this new error handling

Screenshots

Add Fallback Model option only in LLM node error handing

image

Fallback model error handling select model list to fallback

image

Fallback success, LLM node status will stay exception, but we can access model retry information

image image image

Fallback model error handling with empty fallback model list

image image

Fallback model list has been retried and still failed

image image

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods

@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Jan 29, 2026
@github-actions github-actions bot added the web This relates to changes on the web. label Jan 29, 2026
@dosubot dosubot bot added the 💪 enhancement New feature or request label Jan 29, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @CrabSAMA, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the robustness of workflows by introducing an automated fallback mechanism for Large Language Model (LLM) nodes. Instead of requiring manual intervention or complex error branches, users can now specify a sequence of alternative LLM models directly within an LLM node's configuration. This ensures that if the primary model fails, the system will seamlessly attempt to use other models, thereby increasing the resilience and reliability of LLM-powered applications and simplifying workflow design.

Highlights

  • New LLM Fallback Error Strategy: Introduced a new error handling strategy, FALLBACK_MODEL, specifically for LLM nodes. This allows users to define a list of alternative models to try if the primary LLM model fails.
  • Automated Model Retries: When an LLM node configured with the FALLBACK_MODEL strategy encounters an error, the system will automatically attempt to re-run the node using the next model in the defined fallback list. This process continues until a model succeeds or all fallback models are exhausted.
  • Backend Infrastructure Updates: Added FALLBACK_MODEL to the ErrorStrategy enum and FALLBACK_MODEL_INDEX to WorkflowNodeExecutionMetadataKey to track fallback attempts. The ErrorHandler and LLMNode logic were updated to manage and utilize these new fields, including storing the current fallback index in the workflow's variable pool.
  • Frontend User Interface Enhancements: The UI now includes an option to select 'Fallback Model' as an error handling strategy for LLM nodes. Users can configure a list of fallback models, and the workflow run log will display detailed information about each fallback attempt, including which model was used and its status.
  • Comprehensive Testing: New unit and integration tests have been added to validate the functionality of the fallback model strategy, covering various scenarios such as successful fallbacks, exhaustion of fallback models, and correct index tracking.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@CrabSAMA CrabSAMA changed the title Feature/llm fallback feat: LLM node support model list fallback Jan 29, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a robust fallback model mechanism for LLM nodes, which is a great enhancement for workflow reliability. The changes are well-structured across the backend and frontend, with comprehensive test coverage for the new logic. The backend implementation in the ErrorHandler and LLMNode is solid, and the frontend correctly visualizes the fallback attempts. I have a few suggestions for minor improvements regarding code duplication and clarity, but overall, this is an excellent contribution.

return self._handle_abort(event)

# Check if node has fallback_models configured
if not hasattr(node.node_data, "fallback_models") or not node.node_data.fallback_models:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The hasattr(node.node_data, "fallback_models") check is redundant. Since you've already verified that node.node_type is NodeType.LLM on line 241, node.node_data is guaranteed to be an instance of LLMNodeData and will have the fallback_models attribute. The check not node.node_data.fallback_models is sufficient.

Suggested change
if not hasattr(node.node_data, "fallback_models") or not node.node_data.fallback_models:
if not node.node_data.fallback_models:

Comment on lines +207 to +211
fallback_model_index_str = (
fallback_model_index_var.text
if hasattr(fallback_model_index_var, "text")
else str(fallback_model_index_var.value)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic for extracting a string value from a Segment object is duplicated in api/core/workflow/graph_engine/error_handler.py (lines 266-270). To improve maintainability and reduce redundancy, consider extracting this into a shared helper function or a method on the Segment class.

Comment on lines +73 to +76
fallbackDetail.push({
...data,
retry_index: (data.execution_metadata?.fallback_model_index ?? 0),
} as NodeTracing)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

You are assigning fallback_model_index to the retry_index field. This is confusing because they represent different concepts (fallback vs. retry). The FallbackResultPanel component doesn't use this retry_index for displaying the attempt number; it uses the array index instead. To avoid future confusion, it's better to remove this assignment.

          fallbackDetail.push(data as NodeTracing)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💪 enhancement New feature or request size:XXL This PR changes 1000+ lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] LLM node support model list fallback

1 participant