fix: use API key environment variables during model initialization - #1250
Merged
Conversation
Pouyanpi
commented
Jun 27, 2025
Pouyanpi
commented
Jun 27, 2025
There was a problem hiding this comment.
Pull Request Overview
This PR addresses an issue where the API key environment variable was validated but ignored during LLM initialization. Key changes include:
- Adding the _prepare_model_kwargs() helper to extract the API key from environment variables.
- Refactoring _init_llms() to use the new helper and remove duplicated logic.
- Updating tests to verify correct API key handling in both main and non‐main models.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_llmrails.py | Adds tests to validate API key extraction from environment variables and graceful handling when missing. |
| nemoguardrails/rails/llm/llmrails.py | Introduces _prepare_model_kwargs(), removes duplicate env var lookup code in _init_llms(), and updates LLM initialization accordingly. |
Collaborator
Author
|
fix related to #1221 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #1250 +/- ##
===========================================
+ Coverage 69.51% 69.54% +0.02%
===========================================
Files 161 161
Lines 16013 16016 +3
===========================================
+ Hits 11132 11138 +6
+ Misses 4881 4878 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
cparisien
approved these changes
Jun 27, 2025
Pouyanpi
force-pushed
the
fix/api-key-init
branch
from
June 27, 2025 16:06
efe792a to
4be0ce0
Compare
- Add _prepare_model_kwargs() helper to handle API key env vars - Fix duplication in _init_llms() method - Update output parsers to return list instead of tuple - Update self-check actions for new parser interface - Add comprehensive tests for API key functionality Fixes issue where api_key_env_var was validated but ignored during LLM initializationix: use API key environment variables during model initialization- Add _prepare_model_kwargs() helper to handle API key env vars- Fix duplication in _init_llms() method- Update output parsers to return list instead of tuple- Update self-check actions for new parser interface- Add comprehensive tests for API key functionalityFixes issue where api_key_env_var was validated but ignored during LLM initialization
Pouyanpi
force-pushed
the
fix/api-key-init
branch
from
June 27, 2025 16:15
a8bb5cc to
209cf9d
Compare
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.
Fixes issue where api_key_env_var was validated but ignored during LLM initialization