Skip to content

fix(core): add guard for provider metadata; revise exception messages#9927

Merged
ogabrielluiz merged 3 commits into
mainfrom
fix-agent-lfx
Sep 19, 2025
Merged

fix(core): add guard for provider metadata; revise exception messages#9927
ogabrielluiz merged 3 commits into
mainfrom
fix-agent-lfx

Conversation

@ogabrielluiz
Copy link
Copy Markdown
Contributor

@ogabrielluiz ogabrielluiz commented Sep 19, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Prevented crashes in the model provider dropdown when a provider lacks metadata, ensuring reliable model selection.
    • Improved error handling during custom class creation to avoid ambiguous failures.
  • Refactor

    • Enhanced error messages to include the exception type and details for clearer diagnostics without changing behavior or APIs.

…providers are included

Updated the options_metadata list in the AgentComponent to only include keys that exist in the MODELS_METADATA dictionary, enhancing the robustness of the component and preventing potential errors from invalid model providers.
Updated the error message in the create_class function to include the exception type for better clarity during debugging. This change enhances the robustness of error handling in the codebase.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 19, 2025

Walkthrough

Adds a guard when building model provider metadata to avoid missing-key errors and revises exception message formatting in class creation without changing signatures or control flow.

Changes

Cohort / File(s) Summary of Changes
Agent provider metadata guard
src/lfx/src/lfx/components/agents/agent.py
Filters DropdownInput.options_metadata to include only providers present in MODELS_METADATA, preventing KeyError. No other logic or signatures changed.
Validation error message formatting
src/lfx/src/lfx/custom/validate.py
In create_class, generic exception handling now raises ValueError with formatted message: includes exception type and wraps original message in parentheses. No API/signature changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title "@coderabbitai" is an @-mention and does not describe the changes in this pull request (which guard MODELS_METADATA lookups in the agent provider options and adjust the create_class exception message), so it fails to summarize the main change or provide context for reviewers. Because the title is unrelated to the changeset content, the check fails. Replace the title with a concise, single-sentence summary of the primary change; for example, "Guard missing model metadata in agent provider options and improve create_class error message" or "Guard MODELS_METADATA lookup in agent and include exception type in create_class error message." Ensure the new title is specific, short, and focused on the main code change rather than an @-mention.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-agent-lfx

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7df5173 and fbccc16.

📒 Files selected for processing (2)
  • src/lfx/src/lfx/components/agents/agent.py (1 hunks)
  • src/lfx/src/lfx/custom/validate.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Update Starter Projects
  • GitHub Check: Run Ruff Check and Format
  • GitHub Check: Ruff Style Check (3.13)
🔇 Additional comments (3)
src/lfx/src/lfx/components/agents/agent.py (2)

69-70: LGTM! Defensive programming prevents KeyError.

The guard prevents potential KeyError exceptions when a provider exists in MODEL_PROVIDERS_LIST but lacks corresponding metadata in MODELS_METADATA. This is a solid defensive programming practice that improves robustness.

KeyError occurs when trying to access a key that doesn't exist in a dictionary, and using conditional checks like if key in dict is a standard best practice to prevent such errors.


535-535: Duplicate guard implementation - consistent with above change.

This implements the same defensive pattern as line 69, ensuring consistency across the codebase where MODELS_METADATA is accessed.

src/lfx/src/lfx/custom/validate.py (1)

284-284: Improved error message format provides better diagnostics.

The new format "Error creating class. {ExceptionName}({original_message})." is more informative than the previous "Error creating class: {original_message}", as it now includes the exception type name. This helps developers quickly identify the root cause of class creation failures.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot changed the title @coderabbitai fix(core): add guard for provider metadata; revise exception messages Sep 19, 2025
@github-actions github-actions Bot added the bug Something isn't working label Sep 19, 2025
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Sep 19, 2025
@sonarqubecloud
Copy link
Copy Markdown

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 23.25%. Comparing base (bb098a5) to head (f3f09dc).
⚠️ Report is 2 commits behind head on main.

❌ Your project status has failed because the head coverage (45.55%) is below the target coverage (55.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9927   +/-   ##
=======================================
  Coverage   23.25%   23.25%           
=======================================
  Files        1090     1090           
  Lines       39837    39837           
  Branches     5530     5530           
=======================================
  Hits         9264     9264           
  Misses      30402    30402           
  Partials      171      171           
Flag Coverage Δ
backend 45.55% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.
see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Collaborator

@edwinjosechittilappilly edwinjosechittilappilly left a comment

Choose a reason for hiding this comment

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

LGTM

@ogabrielluiz ogabrielluiz added this pull request to the merge queue Sep 19, 2025
@github-actions github-actions Bot added the lgtm This PR has been approved by a maintainer label Sep 19, 2025
Merged via the queue into main with commit ed95b50 Sep 19, 2025
75 of 76 checks passed
@ogabrielluiz ogabrielluiz deleted the fix-agent-lfx branch September 19, 2025 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants