Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/backend/base/langflow/components/anthropic/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ def update_build_config(self, build_config: dotdict, field_value: Any, field_nam
except (ImportError, ValueError, requests.exceptions.RequestException) as e:
logger.exception(f"Error getting model names: {e}")
ids = ANTHROPIC_MODELS
build_config.setdefault("model_name", {})
build_config["model_name"]["options"] = ids
build_config["model_name"]["value"] = ids[0]
build_config["model_name"].setdefault("value", ids[0])
build_config["model_name"]["combobox"] = True
Comment on lines +180 to 183
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Prevent IndexError when no models are returned

ids can be empty after filtering tool-capable models or due to API/listing issues. Accessing ids[0] will raise IndexError. Guard it.

Apply this diff:

-                build_config.setdefault("model_name", {})
-                build_config["model_name"]["options"] = ids
-                build_config["model_name"].setdefault("value", ids[0])
+                model_cfg = build_config.setdefault("model_name", {})
+                model_cfg["options"] = ids
+                if ids:
+                    model_cfg.setdefault("value", ids[0])
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
build_config.setdefault("model_name", {})
build_config["model_name"]["options"] = ids
build_config["model_name"]["value"] = ids[0]
build_config["model_name"].setdefault("value", ids[0])
build_config["model_name"]["combobox"] = True
model_cfg = build_config.setdefault("model_name", {})
model_cfg["options"] = ids
if ids:
model_cfg.setdefault("value", ids[0])
build_config["model_name"]["combobox"] = True
🤖 Prompt for AI Agents
In src/backend/base/langflow/components/anthropic/anthropic.py around lines 180
to 183, the code unconditionally does
build_config["model_name"].setdefault("value", ids[0]) which will raise
IndexError if ids is empty; change this to first set
build_config["model_name"]["options"] = ids, then set the default value to
ids[0] only when ids is non-empty otherwise set a safe fallback (e.g. an empty
string or None) and keep combobox behavior; in short, guard the access to ids[0]
with an if ids: ... else: ... and assign a sensible default value when ids is
empty.

except Exception as e:
msg = f"Error getting model names: {e}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ def update_build_config(self, build_config: dotdict, field_value: Any, field_nam
except (ImportError, ValueError, requests.exceptions.RequestException) as e:
logger.exception(f"Error getting model names: {e}")
ids = GOOGLE_GENERATIVE_AI_MODELS
build_config.setdefault("model_name", {})
build_config["model_name"]["options"] = ids
build_config["model_name"]["value"] = ids[0]
build_config["model_name"].setdefault("value", ids[0])
except Exception as e:
Comment on lines +148 to 151
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid IndexError when ids is empty

ids[0] will throw if the list is empty (e.g., transient API issues or filtering). Add a guard.

Apply this diff:

-                build_config.setdefault("model_name", {})
-                build_config["model_name"]["options"] = ids
-                build_config["model_name"].setdefault("value", ids[0])
+                model_cfg = build_config.setdefault("model_name", {})
+                model_cfg["options"] = ids
+                if ids:
+                    model_cfg.setdefault("value", ids[0])
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
build_config.setdefault("model_name", {})
build_config["model_name"]["options"] = ids
build_config["model_name"]["value"] = ids[0]
build_config["model_name"].setdefault("value", ids[0])
except Exception as e:
model_cfg = build_config.setdefault("model_name", {})
model_cfg["options"] = ids
if ids:
model_cfg.setdefault("value", ids[0])
🤖 Prompt for AI Agents
In src/backend/base/langflow/components/google/google_generative_ai.py around
lines 148-151, the code accesses ids[0] without checking that ids is non-empty
which can raise IndexError; ensure you guard against an empty ids list by
checking if ids and setting build_config["model_name"]["value"] only when ids
has at least one element, otherwise set a safe fallback (e.g., None or an empty
string) or omit the "value" key and optionally log a warning/error so transient
API or filtering yielding an empty list does not crash the process.

msg = f"Error getting model names: {e}"
raise ValueError(msg) from e
Expand Down
3 changes: 2 additions & 1 deletion src/backend/base/langflow/components/groq/groq.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ def update_build_config(self, build_config: dict, field_value: str, field_name:
except (ImportError, ValueError, requests.exceptions.RequestException) as e:
logger.exception(f"Error getting model names: {e}")
ids = GROQ_MODELS
build_config.setdefault("model_name", {})
build_config["model_name"]["options"] = ids
build_config["model_name"]["value"] = ids[0]
build_config["model_name"].setdefault("value", ids[0])
except Exception as e:
Comment on lines +117 to 120
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Guard against empty ids to avoid IndexError

ids can be empty (e.g., transient API failure or aggressive filtering when tool_model_enabled is True). Accessing ids[0] will raise IndexError even inside setdefault. Add a simple guard.

Apply this diff:

-                    build_config.setdefault("model_name", {})
-                    build_config["model_name"]["options"] = ids
-                    build_config["model_name"].setdefault("value", ids[0])
+                    model_cfg = build_config.setdefault("model_name", {})
+                    model_cfg["options"] = ids
+                    if ids:
+                        model_cfg.setdefault("value", ids[0])
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
build_config.setdefault("model_name", {})
build_config["model_name"]["options"] = ids
build_config["model_name"]["value"] = ids[0]
build_config["model_name"].setdefault("value", ids[0])
except Exception as e:
model_cfg = build_config.setdefault("model_name", {})
model_cfg["options"] = ids
if ids:
model_cfg.setdefault("value", ids[0])
except Exception as e:
🤖 Prompt for AI Agents
In src/backend/base/langflow/components/groq/groq.py around lines 117 to 120,
the code unconditionally sets build_config["model_name"]["options"] = ids and
build_config["model_name"].setdefault("value", ids[0]) which will raise
IndexError when ids is empty; add a guard that checks if ids is truthy before
setting "options" and using ids[0] — if ids is empty, set "options" to an empty
list (or omit it) and set "value" to None or a sensible default, or skip those
assignments entirely; ensure this check is inside the same try/except block so
transient failures won't cause an IndexError.

msg = f"Error getting model names: {e}"
raise ValueError(msg) from e
Expand Down