Skip to content

fix(llmrails): handle LLM models without model_kwargs field in isolation #1336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Pouyanpi
Copy link
Collaborator

Description

Fix LLM isolation for models without model_kwargs

Problem:

  • ChatNVIDIA and other strict Pydantic models fail with "ChatNVIDIA" object has no field "model_kwargs" when creating isolated LLM instances for actions
  • FakeLLM test failures due to independent counters in copied instances

Solution:

  • Only attempt to copy model_kwargs if it exists and is not None
  • Don't try to set model_kwargs = {} on models that don't support it
  • FakeLLM now shares response counter across copies to maintain test sequence integrity

Changes:

  • nemoguardrails/rails/llm/llmrails.py: simplified model_kwargs handling in _create_action_llm_copy
  • tests/utils.py: added shared state counter to FakeLLM for consistent test behavior

This fixes the "Failed to create isolated LLM instance" errors when using ChatNVIDIA or other models without model_kwargs field.

- Only copy model_kwargs if it exists and is not None
- Prevents AttributeError for models like ChatNVIDIA that don't have model_kwargs
- Fix FakeLLM to share counter across copied instances for test consistency
@Pouyanpi Pouyanpi added this to the v0.16.0 milestone Aug 15, 2025
@Pouyanpi Pouyanpi self-assigned this Aug 15, 2025
@Pouyanpi Pouyanpi added the bug Something isn't working label Aug 15, 2025
@Pouyanpi Pouyanpi requested a review from tgasser-nv August 15, 2025 16:18
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.70%. Comparing base (949e422) to head (70992d8).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1336      +/-   ##
===========================================
- Coverage    70.70%   70.70%   -0.01%     
===========================================
  Files          161      161              
  Lines        16312    16311       -1     
===========================================
- Hits         11533    11532       -1     
  Misses        4779     4779              
Flag Coverage Δ
python 70.70% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
nemoguardrails/rails/llm/llmrails.py 90.88% <ø> (-0.02%) ⬇️
🚀 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants