feat(llm): add automatic provider inference for LangChain LLMs - #1460
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Collaborator
Author
Add automatic provider name detection from LLM module paths to eliminate manual provider specification. The implementation extracts provider names from LangChain package naming conventions (e.g.,langchain_openai → openai) and handles edge cases including community packages, wrapped classes, and multiple inheritance through MRO traversal.
Pouyanpi
force-pushed
the
feat/llm-provider-inference
branch
from
October 21, 2025 07:55
c77ccf5 to
9ae8a0f
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR adds automatic provider inference for LangChain LLMs by extracting provider names from module paths, eliminating the need for manual provider specification. The implementation follows LangChain's package naming conventions (e.g., langchain_openai → openai) and handles edge cases through MRO traversal.
Key Changes:
- Added
_infer_provider_from_module()to extract provider names from LangChain package naming patterns - Added public
get_llm_provider()API for external provider name retrieval - Updated
_setup_llm_call_info()to automatically infer provider whenmodel_providerisNone
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| nemoguardrails/actions/llm/utils.py | Implements provider inference logic and integrates it into the LLM call setup flow |
| tests/test_actions_llm_utils.py | Comprehensive test suite covering standard providers, community packages, wrapped classes, and inheritance patterns |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Pouyanpi
added a commit
that referenced
this pull request
Oct 28, 2025
tgasser-nv
pushed a commit
that referenced
this pull request
Oct 28, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add automatic provider name detection from LLM module paths to eliminate manual provider specification. The implementation extracts provider names from LangChain package naming conventions (e.g.,langchain_openai → openai) and handles edge cases including community packages, wrapped classes, and multiple inheritance through MRO traversal.
_infer_provider_from_module()to extract provider names from LangChain package conventionsget_llm_provider()API for retrieving provider names_setup_llm_call_info()to automatically infer provider when not explicitly providedTest Plan
model_providerparameter isNone